MCPcopy Create free account
hub / github.com/aboutcode-org/scancode-toolkit / _DeepMapping

Class _DeepMapping

src/licensedcode/_vendor/attr/validators.py:421–440  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

419
420@attrs(repr=False, slots=True, hash=True)
421class _DeepMapping(object):
422 key_validator = attrib(validator=is_callable())
423 value_validator = attrib(validator=is_callable())
424 mapping_validator = attrib(default=None, validator=optional(is_callable()))
425
426 def __call__(self, inst, attr, value):
427 """
428 We use a callable class to be able to change the ``__repr__``.
429 """
430 if self.mapping_validator is not None:
431 self.mapping_validator(inst, attr, value)
432
433 for key in value:
434 self.key_validator(inst, attr, key)
435 self.value_validator(inst, attr, value[key])
436
437 def __repr__(self):
438 return (
439 "<deep_mapping validator for objects mapping {key!r} to {value!r}>"
440 ).format(key=self.key_validator, value=self.value_validator)
441
442
443def deep_mapping(key_validator, value_validator, mapping_validator=None):

Callers 1

deep_mappingFunction · 0.85

Calls 3

attribFunction · 0.85
is_callableFunction · 0.85
optionalFunction · 0.70

Tested by

no test coverage detected