pyvista.core._validation.check.check_instance#
- check_instance(obj, /, classinfo, *, allow_subclass=True, name='Object')[source]#
Check if an object is an instance of the given type or types.
- Parameters:
- obj
Any
Object to check.
- classinfo
type
|tuple
[type
, …] type
or 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
- name
str
, default: “Object” Variable name to use in the error messages if any are raised.
- obj
- 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 import _validation >>> _validation.check_instance(1 + 2j, complex)
Check if an object is an instance of one of several types.
>>> _validation.check_instance("eggs", (int, str))