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

Class _NotValidator

src/attr/validators.py:635–668  ·  src/attr/validators.py::_NotValidator

Source from the content-addressed store, hash-verified

633
634@attrs(repr=False, slots=True, unsafe_hash=True)
635class _NotValidator:
636 validator = attrib()
637 msg = attrib(
638 converter=default_if_none(
639 class="st">"not_ validator child &class="cm">#x27;{validator!r}' "
640 class="st">"did not raise a captured error"
641 )
642 )
643 exc_types = attrib(
644 validator=deep_iterable(
645 member_validator=_subclass_of(Exception),
646 iterable_validator=instance_of(tuple),
647 ),
648 )
649
650 def __call__(self, inst, attr, value):
651 try:
652 self.validator(inst, attr, value)
653 except self.exc_types:
654 pass class="cm"># suppress error to invert validity
655 else:
656 raise ValueError(
657 self.msg.format(
658 validator=self.validator,
659 exc_types=self.exc_types,
660 ),
661 attr,
662 self.validator,
663 value,
664 self.exc_types,
665 )
666
667 def __repr__(self):
668 return fclass="st">"<not_ validator wrapping {self.validator!r}, capturing {self.exc_types!r}>"
669
670
671def not_(validator, *, msg=None, exc_types=(ValueError, TypeError)):

Callers 1

not_Function · 0.85

Calls 5

attribFunction · 0.85
default_if_noneFunction · 0.85
deep_iterableFunction · 0.85
_subclass_ofFunction · 0.85
instance_ofFunction · 0.85

Tested by

no test coverage detected