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

Class _InstanceOfValidator

src/attr/validators.py:93–110  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

91
92@attrs(repr=False, slots=True, unsafe_hash=True)
93class _InstanceOfValidator:
94 type = attrib()
95
96 def __call__(self, inst, attr, value):
97 """
98 We use a callable class to be able to change the ``__repr__``.
99 """
100 if not isinstance(value, self.type):
101 msg = f"'{attr.name}' must be {self.type!r} (got {value!r} that is a {value.__class__!r})."
102 raise TypeError(
103 msg,
104 attr,
105 self.type,
106 value,
107 )
108
109 def __repr__(self):
110 return f"<instance_of validator for type {self.type!r}>"
111
112
113def instance_of(type):

Callers 1

instance_ofFunction · 0.85

Calls 1

attribFunction · 0.85

Tested by

no test coverage detected