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, …]
typeor 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
Notes
The use of
check_instance()is generally preferred as it allows subclasses. Usecheck_type()only for cases where exact types are necessary.Examples
Check if an object is type
dictorset.>>> from pyvista_validation import check_type >>> check_type({'spam': 'eggs'}, (dict, set)) {'spam': 'eggs'}