Skip to content

Commit f6099ca

Browse files
author
Sylvain MARIE
committed
Fixed bug in is_in when the reference object was a non-set container. Fixed #47
1 parent 5a918a3 commit f6099ca

2 files changed

Lines changed: 6 additions & 3 deletions

File tree

valid8/tests/validation_lib/test_validators_collections.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,9 @@ def test_is_in():
1313
with pytest.raises(ValidationFailure):
1414
is_in({'+', '-'})('*')
1515

16+
# also test non-set iterable types
17+
is_in(('+', '-'))('+')
18+
1619

1720
def test_contains():
1821
""" Checks that contains works """

valid8/validation_lib/collections.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
try: # python 3.5+
22
# noinspection PyUnresolvedReferences
3-
from typing import Set, Tuple
3+
from typing import Set, Tuple, Container
44
except ImportError:
55
pass
66

@@ -158,7 +158,7 @@ def __init__(self, wrong_value, allowed_values, **kwargs):
158158
**kwargs)
159159

160160

161-
def is_in(allowed_values # type: Set
161+
def is_in(allowed_values # type: Container
162162
):
163163
"""
164164
'Values in' validation_function generator.
@@ -174,7 +174,7 @@ def is_in_allowed_values(x):
174174
# raise ValidationFailure('is_in: x in ' + str(allowed_values) + ' does not hold for x=' + str(x))
175175
raise NotInAllowedValues(wrong_value=x, allowed_values=allowed_values)
176176

177-
is_in_allowed_values.__name__ = 'is_in_%s' % allowed_values
177+
is_in_allowed_values.__name__ = 'is_in_%s' % (allowed_values, )
178178
return is_in_allowed_values
179179

180180

0 commit comments

Comments
 (0)