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

Class _DeepIterable

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

Source from the content-addressed store, hash-verified

372
373@attrs(repr=False, slots=True, hash=True)
374class _DeepIterable(object):
375 member_validator = attrib(validator=is_callable())
376 iterable_validator = attrib(
377 default=None, validator=optional(is_callable())
378 )
379
380 def __call__(self, inst, attr, value):
381 """
382 We use a callable class to be able to change the ``__repr__``.
383 """
384 if self.iterable_validator is not None:
385 self.iterable_validator(inst, attr, value)
386
387 for member in value:
388 self.member_validator(inst, attr, member)
389
390 def __repr__(self):
391 iterable_identifier = (
392 ""
393 if self.iterable_validator is None
394 else " {iterable!r}".format(iterable=self.iterable_validator)
395 )
396 return (
397 "<deep_iterable validator for{iterable_identifier}"
398 " iterables of {member!r}>"
399 ).format(
400 iterable_identifier=iterable_identifier,
401 member=self.member_validator,
402 )
403
404
405def deep_iterable(member_validator, iterable_validator=None):

Callers 1

deep_iterableFunction · 0.85

Calls 3

attribFunction · 0.85
is_callableFunction · 0.85
optionalFunction · 0.70

Tested by

no test coverage detected