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

Function _subclass_of

src/attr/validators.py:617–631  ·  view source on GitHub ↗

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

(type)

Source from the content-addressed store, hash-verified

615
616
617def _subclass_of(type):
618 """
619 A validator that raises a `TypeError` if the initializer is called with a
620 wrong type for this particular attribute (checks are performed using
621 `issubclass` therefore it's also valid to pass a tuple of types).
622
623 Args:
624 type (type | tuple[type, ...]): The type(s) to check for.
625
626 Raises:
627 TypeError:
628 With a human readable error message, the attribute (of type
629 `attrs.Attribute`), the expected type, and the value it got.
630 """
631 return _SubclassOfValidator(type)
632
633
634@attrs(repr=False, slots=True, unsafe_hash=True)

Callers 5

test_successMethod · 0.90
test_subclassMethod · 0.90
test_failMethod · 0.90
test_reprMethod · 0.90
_NotValidatorClass · 0.85

Calls 1

Tested by 4

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