MCPcopy
hub / github.com/alecthomas/voluptuous / Maybe

Function Maybe

voluptuous/validators.py:622–635  ·  view source on GitHub ↗

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)

Source from the content-addressed store, hash-verified

620
621
622def 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
638class Range(object):

Callers 4

test_reprFunction · 0.90
test_maybeFunction · 0.90
test_maybe_accepts_msgFunction · 0.90

Calls 1

AnyClass · 0.85

Tested by 4

test_reprFunction · 0.72
test_maybeFunction · 0.72
test_maybe_accepts_msgFunction · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…