| 91 | |
| 92 | @attrs(repr=False, slots=True, unsafe_hash=True) |
| 93 | class _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 | |
| 113 | def instance_of(type): |