erlab.utils.misc

Utilities that don’t fit in any other category.

Functions

accepts_kwarg(func, name, *[, strict])

Return True if func can be called with keyword argument name.

emit_user_level_warning(message[, category])

Emit a warning at the user level by inspecting the stack trace.

get_tqdm()

Get the appropriate tqdm module.

is_interactive()

Check if the code is running in an interactive environment.

is_newer_version(version_str)

Check if a version string is newer than the current installed erlab version.

is_sequence_of(val, element_type)

Check if the given object is a sequence of elements of the specified type.

open_in_file_manager(path)

Reveal a path in the system's file manager.

erlab.utils.misc.accepts_kwarg(func, name, *, strict=True)[source]

Return True if func can be called with keyword argument name.

Parameters:
  • func (Callable) – The callable to inspect.

  • name (str) – The name of the keyword argument to check for.

  • strict (bool, default: True) – If True, only return True if name is explicitly defined as a keyword parameter in func’s signature. If False, also return True if func accepts arbitrary keyword arguments via **kwargs.

erlab.utils.misc.emit_user_level_warning(message, category=None)[source]

Emit a warning at the user level by inspecting the stack trace.

erlab.utils.misc.get_tqdm()[source]

Get the appropriate tqdm module.

For frozen packages, we cannot use tqdm.auto since it causes issues with incomplete IPython installations.

erlab.utils.misc.is_interactive()[source]

Check if the code is running in an interactive environment.

Returns:

boolTrue if the code is running in an interactive environment (IPython), False otherwise.

Return type:

bool

erlab.utils.misc.is_newer_version(version_str)[source]

Check if a version string is newer than the current installed erlab version.

erlab.utils.misc.is_sequence_of(val, element_type)[source]

Check if the given object is a sequence of elements of the specified type.

Parameters:
  • val (Any) – The object to check.

  • element_type (type[TypeVar(_T)]) – The type of elements that the sequence should contain.

Returns:

boolTrue if val is a sequence and all elements in the sequence are of type element_type, False otherwise.

Return type:

TypeGuard[Sequence[_T]]

Examples

>>> is_sequence_of([1, 2, 3], int)
True
>>> is_sequence_of([1, 2, "3"], int)
False
erlab.utils.misc.open_in_file_manager(path)[source]

Reveal a path in the system’s file manager.

Parameters:

path (str | PathLike) – Path to the file or folder.