openmnglab.util.iterables.ensure_iterable#

openmnglab.util.iterables.ensure_iterable(inp: Iterable[T] | T | None, type: Type[T]) Iterable[T][source]#

Ensures that the input is an iterable of the given type.

Warning

Only works if inp is either None, of type type or an iterable of said type (see checks)

See also

ensure_sequence() for a varaint of this function which will ensure a sequence (including automatic conversion from iterable to tuple)

See also

unpack_sequence() for the inverse operation for sequences

performs the following checks:

  1. inp is None: returns an empty tuple

  2. inp is an instace of type: returns a tuple with inp as sole element

  3. return inp without modification

Parameters:
  • inp – Iterable, a single item of type type or None

  • type – Base type of data in inp

Returns:

An iterable of element(s) from inp or an empty tuple if inp is None