pyvista_validation.check.check_instance

Contents

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, …]

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.

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'