Skip to content

Commit ffd9f01

Browse files
Merge pull request #256 from phenobarbital/new-exports
simple fix on constraints validations max,min will be inclusive
2 parents a9b236e + c716b2b commit ffd9f01

3 files changed

Lines changed: 12 additions & 8 deletions

File tree

datamodel/validation.pyx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -424,7 +424,7 @@ cdef dict _validate_constraints(
424424
)
425425

426426
# Minimum value validation (greater than)
427-
if min_val is not None and value <= min_val:
427+
if min_val is not None and value < min_val: # inclusive
428428
return _create_error(
429429
name,
430430
value,
@@ -434,7 +434,7 @@ cdef dict _validate_constraints(
434434
)
435435

436436
# Maximum value validation (less than)
437-
if max_val is not None and value >= max_val:
437+
if max_val is not None and value > max_val: # inclusive
438438
return _create_error(
439439
name,
440440
value,

datamodel/version.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
'simple library based on python +3.8 to use Dataclass-syntax'
77
'for interacting with Data'
88
)
9-
__version__ = '0.10.15'
9+
__version__ = '0.10.16'
1010
__copyright__ = 'Copyright (c) 2020-2024 Jesus Lara'
1111
__author__ = 'Jesus Lara'
1212
__author_email__ = 'jesuslarag@gmail.com'

examples/basic.py

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -31,11 +31,15 @@ class newPoint(BaseModel, intSum):
3131
x: int = Field(default=0, min=0, max=10)
3232
y: Union[int, None] = Field(default=0, min=0, max=10)
3333

34-
a = newPoint(x=10, y=10)
35-
print(a)
36-
print(fields(a))
37-
print('IS a Dataclass?: ', is_dataclass(a))
38-
print(a.get_coordinate())
34+
try:
35+
p = newPoint(x=10, y=10)
36+
except ValidationError as e:
37+
print(e.payload)
38+
39+
print(p)
40+
print(fields(p), ' Coords: ', p.x, p.y, type(p.x), type(p.y))
41+
print('IS a Dataclass?: ', is_dataclass(p))
42+
print(p.get_coordinate())
3943

4044
class coordinate(BaseModel, intSum):
4145
latitude: float

0 commit comments

Comments
 (0)