helper#


This module contains various helper functions.

count_none(*args: Any) int[source]#

Counts the number of arguments that are None

Parameters:

args – various arguments

Returns:

the number of arguments that are None

count_not_none(*args: Any) int[source]#

Counts the number of arguments that are not None

Parameters:

args – various arguments

Returns:

the number of arguments that are not None

any_none(*args: Any) bool[source]#
Parameters:

args – various arguments

Returns:

True if any of the arguments are None, False otherwise

all_none(*args: Any) bool[source]#
Parameters:

args – various arguments

Returns:

True if all of the arguments are None, False otherwise

check_not_nan_dict(d: dict)[source]#

Raises ValueError if any of the values in the given dictionary are NaN, reporting the respective keys

Parameters:

d – a dictionary mapping to floats that are to be checked for NaN

contains_any(container: Union[Container, Iterable], items: Sequence) bool[source]#
mark_used(*args)[source]#

Utility function to mark identifiers as used. The function does nothing.

Parameters:

args – pass identifiers that shall be marked as used here

flatten_arguments(args: Sequence[Union[T, Sequence[T]]]) List[T][source]#

Main use case is to support both interfaces of the type f(T1, T2, …) and f([T1, T2, …]) simultaneously. It is assumed that if the latter form is passed, the arguments are either in a list or a tuple. Moreover, T cannot be a tuple or a list itself.

Overall this function is not all too safe and one should be aware of what one is doing when using it

kwarg_if_not_none(arg_name: str, arg_value: Any) Dict[str, Any][source]#

Supports the optional passing of a kwarg, returning a non-empty dictionary with the kwarg only if the value is not None.

This can be helpful to improve backward compatibility for cases where a kwarg was added later but old implementations weren’t updated to have it, such that an exception will be raised only if the kwarg is actually used.

Parameters:
  • arg_name – the argument name

  • arg_value – the value

Returns:

a dictionary containing the kwarg or, if the value is None, an empty dictionary