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)
| 275 | |
| 276 | |
| 277 | def 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) |
no test coverage detected