pyvista_validation.check.check_iterable_items

pyvista_validation.check.check_iterable_items#

pyvista_validation.check.check_iterable_items(iterable_obj, /, item_type, *, allow_subclass=True, name='Iterable')#

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.

Returns:
Iterable

The input, unchanged. Type checkers see its items as instances of item_type.

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))
(1, 2, 3.0)

Check if a list only has list elements.

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