pyvista.core._validation.check.check_instance

Contents

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:
objAny

Object to check.

classinfotype | 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 by classinfo

or any of its subclasses. Otherwise, subclasses are not allowed.

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 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))