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
inpis eitherNone, of typetypeor 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 sequencesperforms the following checks:
inpisNone: returns an empty tupleinpis an instace oftype: returns a tuple withinpas sole elementreturn
inpwithout modification
- Parameters:
inp – Iterable, a single item of type
typeorNonetype – Base type of data in
inp
- Returns:
An iterable of element(s) from
inpor an empty tuple ifinpisNone