| 459 | |
| 460 | @attrs(repr=False, frozen=True, slots=True) |
| 461 | class _NumberValidator: |
| 462 | bound = attrib() |
| 463 | compare_op = attrib() |
| 464 | compare_func = attrib() |
| 465 | |
| 466 | def __call__(self, inst, attr, value): |
| 467 | """ |
| 468 | We use a callable class to be able to change the ``__repr__``. |
| 469 | """ |
| 470 | if not self.compare_func(value, self.bound): |
| 471 | msg = f"'{attr.name}' must be {self.compare_op} {self.bound}: {value}" |
| 472 | raise ValueError(msg) |
| 473 | |
| 474 | def __repr__(self): |
| 475 | return f"<Validator for x {self.compare_op} {self.bound}>" |
| 476 | |
| 477 | |
| 478 | def lt(val): |