pyvista_validation.check.check_iterable_items

pyvista_validation.check.check_iterable_items#

pyvista_validation.check.check_iterable_items(iterable_obj: Iterable[Any], /, item_type: type | tuple[type, ...], *, allow_subclass: bool = True, name: str = 'Iterable') None#

Check if an iterable’s items all have a specified type.

Parameters:
iterable_objIterable

Iterable to check.

item_typetype | tuple[type, …]

Class types to check for. Each element of the sequence must have the type or one of the types specified.

allow_subclassbool, default: True

If True, the type of the iterable items must be any of the given types or a subclass thereof. Otherwise, subclasses are not allowed.

namestr, default: “Iterable”

Variable name to use in the error messages if any are raised.

Raises:
TypeError

If any of the items in the iterable have an incorrect type.

Examples

Check if a tuple only has int or float elements.

>>> from pyvista_validation import check_iterable_items
>>> check_iterable_items((1, 2, 3.0), (int, float))

Check if a list only has list elements.

>>> import pyvista_validation
>>> check_iterable_items([[1], [2], [3]], list)