| 566 | |
| 567 | @attrs(repr=False, frozen=True, slots=True) |
| 568 | class _MinLengthValidator: |
| 569 | min_length = attrib() |
| 570 | |
| 571 | def __call__(self, inst, attr, value): |
| 572 | """ |
| 573 | We use a callable class to be able to change the ``__repr__``. |
| 574 | """ |
| 575 | if len(value) < self.min_length: |
| 576 | msg = f"Length of '{attr.name}' must be >= {self.min_length}: {len(value)}" |
| 577 | raise ValueError(msg) |
| 578 | |
| 579 | def __repr__(self): |
| 580 | return f"<min_len validator for {self.min_length}>" |
| 581 | |
| 582 | |
| 583 | def min_len(length): |