Validate that the object matches given validator or is None. :raises Invalid: If the value does not match the given validator and is not None. >>> s = Schema(Maybe(int)) >>> s(10) 10 >>> with raises(Invalid): ... s("string")
(validator: Schemable, msg: typing.Optional[str] = None)
| 620 | |
| 621 | |
| 622 | def Maybe(validator: Schemable, msg: typing.Optional[str] = None): |
| 623 | """Validate that the object matches given validator or is None. |
| 624 | |
| 625 | :raises Invalid: If the value does not match the given validator and is not |
| 626 | None. |
| 627 | |
| 628 | >>> s = Schema(Maybe(int)) |
| 629 | >>> s(10) |
| 630 | 10 |
| 631 | >>> with raises(Invalid): |
| 632 | ... s("string") |
| 633 | |
| 634 | """ |
| 635 | return Any(None, validator, msg=msg) |
| 636 | |
| 637 | |
| 638 | class Range(object): |
searching dependent graphs…