-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
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
Added le
and ge
bounds to constrained numerics.
#194
Conversation
Codecov Report
@@ Coverage Diff @@
## master #194 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 10 10
Lines 1149 1172 +23
Branches 214 218 +4
=====================================
+ Hits 1149 1172 +23 |
Probably we want to update the docs as well. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Otherwise this looks great, just one small change, and also could you update HISTORY.rst
.
@Gr1N wrote some of this code so might have some feedback too.
tests/test_types.py
Outdated
def test_number_gt(): | ||
class Model(BaseModel): | ||
a: conint(gt=-1) = 0 | ||
class TestNumberBounds: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I understand where you're coming from, but let's stick with no classes in tests for simplicity.
And docs, yes. |
pydantic/types.py
Outdated
try: | ||
assert new_cls.gt is None or new_cls.ge is None, ('gt', 'ge') | ||
assert new_cls.lt is None or new_cls.le is None, ('lt', 'le') | ||
except AssertionError as exception: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
except AssertionError as e:
...
raise errors.ConfigError(...) from e
tests/test_types.py
Outdated
@@ -12,6 +12,7 @@ | |||
from pydantic import (DSN, UUID1, UUID3, UUID4, UUID5, BaseModel, EmailStr, NameEmail, NegativeFloat, NegativeInt, | |||
PositiveFloat, PositiveInt, PyObject, StrictStr, ValidationError, condecimal, confloat, conint, | |||
constr, create_model) | |||
from pydantic.errors import ConfigError |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
from pydantic import ConfigError
pydantic/types.py
Outdated
@@ -175,19 +175,34 @@ def validate(cls, value, values, **kwarg): | |||
return make_dsn(**kwargs) | |||
|
|||
|
|||
class ConstrainedInt(int): | |||
class ConstrainedMeta(type): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe better to change name of class? Something like ConstrainedNumberMeta
or just NumberMeta
?
Addressed all comments, I think. |
docs/examples/exotic.py
Outdated
@@ -16,10 +16,12 @@ class Model(BaseModel): | |||
strip_str: constr(strip_whitespace=True) | |||
|
|||
big_int: conint(gt=1000, lt=1024) = None | |||
# inclusive: conint(ge=1000, le=1024) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove
Anything else?
…On Thu, 7 Jun 2018 at 16:30, Samuel Colvin ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In docs/examples/exotic.py
<#194 (comment)>:
> @@ -16,10 +16,12 @@ class Model(BaseModel):
strip_str: constr(strip_whitespace=True)
big_int: conint(gt=1000, lt=1024) = None
+ # inclusive: conint(ge=1000, le=1024)
remove
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
<#194 (review)>,
or mute the thread
<https://github.com/notifications/unsubscribe-auth/AAIKZDXr02EHf109uMBlgD5bO08C2xx-ks5t6TkCgaJpZM4UeXV_>
.
|
great, thank you very much. |
See discussion #174.