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

Function optional

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

A validator that makes an attribute optional. An optional attribute is one which can be set to ``None`` in addition to satisfying the requirements of the sub-validator. :param validator: A validator (or a list of validators) that is used for non-``None`` values. :type

(validator)

Source from the content-addressed store, hash-verified

275
276
277def optional(validator):
278 """
279 A validator that makes an attribute optional. An optional attribute is one
280 which can be set to ``None`` in addition to satisfying the requirements of
281 the sub-validator.
282
283 :param validator: A validator (or a list of validators) that is used for
284 non-``None`` values.
285 :type validator: callable or `list` of callables.
286
287 .. versionadded:: 15.1.0
288 .. versionchanged:: 17.1.0 *validator* can be a list of validators.
289 """
290 if isinstance(validator, list):
291 return _OptionalValidator(_AndValidator(validator))
292 return _OptionalValidator(validator)
293
294
295@attrs(repr=False, slots=True, hash=True)

Callers 2

_DeepIterableClass · 0.70
_DeepMappingClass · 0.70

Calls 2

_OptionalValidatorClass · 0.85
_AndValidatorClass · 0.85

Tested by

no test coverage detected