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

Class _DeepMapping

src/attr/validators.py:388–407  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

386
387@attrs(repr=False, slots=True, unsafe_hash=True)
388class _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
410def deep_mapping(

Callers 1

deep_mappingFunction · 0.85

Calls 3

attribFunction · 0.85
is_callableFunction · 0.85
optionalFunction · 0.70

Tested by

no test coverage detected