pyvista_validation.check.check_instance#
- pyvista_validation.check.check_instance(obj: object, /, classinfo: type | tuple[type, ...], *, allow_subclass: bool = True, name: str = 'Object') None#
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.
- 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)
Check if an object is an instance of one of several types.
>>> check_instance('eggs', (int, str))