pyvista_validation.check.check_type

Contents

pyvista_validation.check.check_type#

pyvista_validation.check.check_type(obj, /, classinfo, *, name='Object')#

Check if an object is one of the given type or types.

Parameters:
objAny

Object to check.

classinfotype | tuple[type, …]

type or tuple of types. Object must be one of the types.

namestr, default: “Object”

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

Returns:
object

The input, unchanged. Type checkers see it as an instance of classinfo.

Raises:
TypeError

If object is not any of the given types.

See also

check_instance

Notes

The use of check_instance() is generally preferred as it allows subclasses. Use check_type() only for cases where exact types are necessary.

Examples

Check if an object is type dict or set.

>>> from pyvista_validation import check_type
>>> check_type({'spam': 'eggs'}, (dict, set))
{'spam': 'eggs'}