Skip to content

Commit

Permalink
Replace Maybe class with a function
Browse files Browse the repository at this point in the history
The Any class can be compiled by voluptuous whereas Maybe cannot. Since it's
just an alias to Any(None, v), replace it with that directly.
  • Loading branch information
jd committed Dec 30, 2017
1 parent 0dad58b commit cd4f2cd
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 12 deletions.
2 changes: 1 addition & 1 deletion voluptuous/tests/tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -492,7 +492,7 @@ def test_repr():
)
assert_equal(repr(coerce_), "Coerce(int, msg='moo')")
assert_equal(repr(all_), "All('10', Coerce(int, msg=None), msg='all msg')")
assert_equal(repr(maybe_int), "Maybe(%s)" % str(int))
assert_equal(repr(maybe_int), "Any(None, %s, msg=None)" % str(int))


def test_list_validation_messages():
Expand Down
13 changes: 2 additions & 11 deletions voluptuous/validators.py
Original file line number Diff line number Diff line change
Expand Up @@ -485,7 +485,7 @@ def PathExists(v):
raise PathInvalid("Not a Path")


class Maybe(object):
def Maybe(validator):
"""Validate that the object matches given validator or is None.
:raises Invalid: if the value does not match the given validator and is not
Expand All @@ -498,16 +498,7 @@ class Maybe(object):
... s("string")
"""

def __init__(self, validator):
self.validator = validator
self.schema = Any(None, validator)

def __call__(self, v):
return self.schema(v)

def __repr__(self):
return 'Maybe(%s)' % self.validator
return Any(None, validator)


class Range(object):
Expand Down

0 comments on commit cd4f2cd

Please sign in to comment.