| 386 | |
| 387 | @attrs(repr=False, slots=True, unsafe_hash=True) |
| 388 | class _DeepMapping: |
| 389 | key_validator = attrib(validator=optional(is_callable())) |
| 390 | value_validator = attrib(validator=optional(is_callable())) |
| 391 | mapping_validator = attrib(validator=optional(is_callable())) |
| 392 | |
| 393 | def __call__(self, inst, attr, value): |
| 394 | """ |
| 395 | We use a callable class to be able to change the ``__repr__``. |
| 396 | """ |
| 397 | if self.mapping_validator is not None: |
| 398 | self.mapping_validator(inst, attr, value) |
| 399 | |
| 400 | for key in value: |
| 401 | if self.key_validator is not None: |
| 402 | self.key_validator(inst, attr, key) |
| 403 | if self.value_validator is not None: |
| 404 | self.value_validator(inst, attr, value[key]) |
| 405 | |
| 406 | def __repr__(self): |
| 407 | return f"<deep_mapping validator for objects mapping {self.key_validator!r} to {self.value_validator!r}>" |
| 408 | |
| 409 | |
| 410 | def deep_mapping( |
no test coverage detected