Skip to main content

set_if_exists

Given a dict d sets the key k with value of config v, if the config value v is set and return the updated dictionary.

def set_if_exists(
d: dict,
k: str,
val: typing.Any
) - > dict

Given a dict d sets the key k with value of config v, if the config value v is set and return the updated dictionary.

Parameters

NameTypeDescription
ddictThe dictionary to which the key-value pair might be added.
kstrThe key to set in the dictionary d.
valtyping.AnyThe value to associate with the key k if it exists. A value is considered to exist if it is a boolean or evaluates to true when converted to a boolean (e.g., not None, not an empty string, not 0).

Returns

TypeDescription
dictThe dictionary d after potentially setting the key k with val.