pyvista_validation.check.check_instance#
- pyvista_validation.check.check_instance(obj, /, classinfo, *, allow_subclass=True, name='Object')#
Check if an object is an instance of the given type or types.
- Parameters:
- objAny
Object to check.
- classinfotype | tuple[type, …]
typeor tuple of types. Object must be an instance of one of the types.- allow_subclassbool, default: True
- If
True, the object’s type must be specified byclassinfo or any of its subclasses. Otherwise, subclasses are not allowed.
- If
- 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 an instance of any of the given types.
Examples
Check if an object is an instance of
complex.>>> from pyvista_validation import check_instance >>> check_instance(1 + 2j, complex) (1+2j)
Check if an object is an instance of one of several types.
>>> check_instance('eggs', (int, str)) 'eggs'