Skip to content

Commit 7793d81

Browse files
committed
range -> between in order to avoid confusion with builtin range
1 parent 7b91a9b commit 7793d81

5 files changed

Lines changed: 22 additions & 23 deletions

File tree

‎docs/index.rst‎

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,6 +63,12 @@ ValidationFailure object also holds all the arguments passed to original functio
6363

6464

6565

66+
between
67+
-------
68+
69+
.. module:: validators.between
70+
71+
.. autofunction:: between
6672

6773

6874
email
@@ -100,13 +106,6 @@ mac_address
100106

101107
.. autofunction:: mac_address
102108

103-
range
104-
-----
105-
106-
.. module:: validators.range
107-
108-
.. autofunction:: range
109-
110109

111110
truthy
112111
------
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
(12, 12, 12)
1111
])
1212
def test_returns_true_on_valid_range(value, min, max):
13-
assert validators.range(value, min=min, max=max)
13+
assert validators.between(value, min=min, max=max)
1414

1515

1616
@pytest.mark.parametrize(('value', 'min', 'max'), [
@@ -19,7 +19,7 @@ def test_returns_true_on_valid_range(value, min, max):
1919
])
2020
def test_raises_assertion_error_for_invalid_args(value, min, max):
2121
with pytest.raises(AssertionError):
22-
assert validators.range(value, min=min, max=max)
22+
assert validators.between(value, min=min, max=max)
2323

2424

2525
@pytest.mark.parametrize(('value', 'min', 'max'), [
@@ -28,5 +28,5 @@ def test_raises_assertion_error_for_invalid_args(value, min, max):
2828
(12, 13, None)
2929
])
3030
def test_returns_failed_validation_on_invalid_range(value, min, max):
31-
result = validators.range(value, min=min, max=max)
31+
result = validators.between(value, min=min, max=max)
3232
assert isinstance(result, validators.ValidationFailure)

‎tests/test_validation_failure.py‎

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44

55
obj_repr = (
6-
"ValidationFailure(func=range"
6+
"ValidationFailure(func=between"
77
)
88

99

1010
class TestValidationFailure(object):
1111
def setup_method(self, method):
12-
self.obj = validators.range(3, min=4, max=5)
12+
self.obj = validators.between(3, min=4, max=5)
1313

1414
def test_boolean_coerce(self):
1515
assert not bool(self.obj)

‎validators/__init__.py‎

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,22 @@
1+
from .between import between
12
from .email import email
23
from .extremes import Min, Max
34
from .ip_address import ipv4, ipv6
45
from .length import length
56
from .mac_address import mac_address
6-
from .range import range
77
from .truthy import truthy
8-
from .utils import ValidationFailure, validator
98
from .url import url
9+
from .utils import ValidationFailure, validator
1010
from .uuid import uuid
1111

1212

1313
__all__ = (
14+
between,
15+
email,
1416
ipv4,
1517
ipv6,
16-
email,
1718
length,
1819
mac_address,
19-
range,
2020
truthy,
2121
url,
2222
uuid,
Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33

44

55
@validator
6-
def range(value, min=None, max=None):
6+
def between(value, min=None, max=None):
77
"""
8-
Validates that a number is of a minimum and/or maximum value, inclusive.
8+
Validates that a number is between minimum and/or maximum value.
99
This will work with any comparable type, such as floats, decimals and dates
1010
not just integers.
1111
12-
This validator is based on `WTForms NumberRange validator`_.
12+
This validator is originally based on `WTForms NumberRange validator`_.
1313
1414
.. _WTForms NumberRange validator:
1515
https://github.com/wtforms/wtforms/blob/master/wtforms/validators.py
@@ -18,15 +18,15 @@ def range(value, min=None, max=None):
1818
1919
>>> import validators
2020
21-
>>> assert validators.range(5, min=2)
21+
>>> assert validators.between(5, min=2)
2222
23-
>>> assert validators.range(13.2, min=13, max=14)
23+
>>> assert validators.between(13.2, min=13, max=14)
2424
25-
>>> assert not validators.range(500, max=400)
25+
>>> assert not validators.between(500, max=400)
2626
2727
>>> from datetime import datetime
2828
29-
>>> assert validator.range(
29+
>>> assert validator.between(
3030
... datetime(2000, 11, 11),
3131
... min=datetime(1999, 11, 11)
3232
... )

0 commit comments

Comments
 (0)