Skip to content

Commit

Permalink
set int default max 2**64-1
Browse files Browse the repository at this point in the history
  • Loading branch information
guyskk committed Dec 13, 2023
1 parent 27bacfb commit 5e877f9
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 7 deletions.
8 changes: 5 additions & 3 deletions src/validr/_validator_c.pyx
Original file line number Diff line number Diff line change
Expand Up @@ -760,13 +760,15 @@ def any_validator(compiler, **ignore_kwargs):
return any_validate


MAX_INT = 2**64 - 1

@validator(accept=(int, float, str), output=int)
def int_validator(compiler, min=-sys.maxsize, max=sys.maxsize):
def int_validator(compiler, min=-MAX_INT, max=MAX_INT):
"""Validate int or convert string to int
Args:
min (int): the min value, default -sys.maxsize
max (int): the max value, default sys.maxsize
min (int): the min value, default -(2**64 - 1)
max (int): the max value, default (2**64 - 1)
"""
min, max = int(min), int(max)

Expand Down
10 changes: 6 additions & 4 deletions tests/validators/test_int.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import sys
from validr import T

from . import case

MAX_INT = 2**64 - 1


@case({
T.int.min(0).max(9): [
Expand All @@ -11,10 +13,10 @@
[-1, 10, 'abc']
],
T.int: [
(sys.maxsize, sys.maxsize),
(-sys.maxsize, -sys.maxsize),
(MAX_INT, MAX_INT),
(-MAX_INT, -MAX_INT),
(0, 0),
[sys.maxsize + 1, -sys.maxsize - 1, float('INF'), float('NAN')]
[MAX_INT + 1, -MAX_INT - 1, float('INF'), float('NAN')]
]
})
def test_int():
Expand Down

0 comments on commit 5e877f9

Please sign in to comment.