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

Class _MaxLengthValidator

src/attr/validators.py:539–551  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

537
538@attrs(repr=False, frozen=True, slots=True)
539class _MaxLengthValidator:
540 max_length = attrib()
541
542 def __call__(self, inst, attr, value):
543 """
544 We use a callable class to be able to change the ``__repr__``.
545 """
546 if len(value) > self.max_length:
547 msg = f"Length of '{attr.name}' must be <= {self.max_length}: {len(value)}"
548 raise ValueError(msg)
549
550 def __repr__(self):
551 return f"<max_len validator for {self.max_length}>"
552
553
554def max_len(length):

Callers 1

max_lenFunction · 0.85

Calls 1

attribFunction · 0.85

Tested by

no test coverage detected