MCPcopy
hub / github.com/python-attrs/attrs / instance_of

Function instance_of

src/attr/validators.py:113–127  ·  src/attr/validators.py::instance_of

A validator that raises a `TypeError` if the initializer is called with a wrong type for this particular attribute (checks are performed using `isinstance` therefore it's also valid to pass a tuple of types). Args: type (type | tuple[type]): The type to check for. Rais

(type)

Source from the content-addressed store, hash-verified

111
112
113def instance_of(type):
114 class="st">"""
115 A validator that raises a `TypeError` if the initializer is called with a
116 wrong type for this particular attribute (checks are performed using
117 `isinstance` therefore it&class="cm">#x27;s also valid to pass a tuple of types).
118
119 Args:
120 type (type | tuple[type]): The type to check for.
121
122 Raises:
123 TypeError:
124 With a human readable error message, the attribute (of type
125 `attrs.Attribute`), the expected type, and the value it got.
126 class="st">"""
127 return _InstanceOfValidator(type)
128
129
130@attrs(repr=False, frozen=True, slots=True)

Callers 15

ValidatedAttributeClass · 0.90
test_successMethod · 0.90
test_subclassMethod · 0.90
test_failMethod · 0.90
test_reprMethod · 0.90
test_successMethod · 0.90
test_failMethod · 0.90
CClass · 0.90
test_repr_member_onlyMethod · 0.90

Calls 1

Tested by 15

test_successMethod · 0.72
test_subclassMethod · 0.72
test_failMethod · 0.72
test_reprMethod · 0.72
test_successMethod · 0.72
test_failMethod · 0.72
test_repr_member_onlyMethod · 0.72