Skip to content

Misc

Use libbot.utils.misc to import the below functions.

nested_delete(target, *path)

Delete the key by its path.

Parameters:

Name Type Description Default
target dict[str, Any]

Dictionary to perform the modification on.

required

Raises:

Type Description
KeyError

Key is not found under the provided path.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Modified dictionary.

nested_set(target, value, *path, create_missing=True)

Set the key by its path to the value

Parameters:

Name Type Description Default
target dict[str, Any]

Dictionary to perform the modification on.

required
value Any

New value.

required
*path str

Path to the key.

()
create_missing bool

Create keys on the way if they're missing. Defaults to True.

True

Raises:

Type Description
KeyError

Key is not found under the provided path.

Returns:

Type Description
dict[str, Any]

dict[str, Any]: Modified dictionary.

supports_argument(func, arg_name)

Check whether a function has a specific argument.

Parameters:

Name Type Description Default
func Callable[..., Any]

Function to be inspected.

required
arg_name str

Argument to be checked.

required

Returns:

Name Type Description
bool bool

True if argument is supported and False if not.