Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Replace Maybe class with a function #319

Merged
merged 1 commit into from
Dec 31, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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