Skip to content
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

Merged
merged 4 commits into from
Jun 8, 2018

Conversation

jaheba
Copy link
Contributor

@jaheba jaheba commented Jun 7, 2018

See discussion #174.

@codecov
Copy link

codecov bot commented Jun 7, 2018

Codecov Report

Merging #194 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master   #194   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          10     10           
  Lines        1149   1172   +23     
  Branches      214    218    +4     
=====================================
+ Hits         1149   1172   +23

@jaheba
Copy link
Contributor Author

jaheba commented Jun 7, 2018

Probably we want to update the docs as well.

Copy link
Member

@samuelcolvin samuelcolvin left a 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.

def test_number_gt():
class Model(BaseModel):
a: conint(gt=-1) = 0
class TestNumberBounds:
Copy link
Member

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.

@samuelcolvin
Copy link
Member

And docs, yes.

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:
Copy link
Contributor

@Gr1N Gr1N Jun 7, 2018

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

@@ -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
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

from pydantic import ConfigError

@@ -175,19 +175,34 @@ def validate(cls, value, values, **kwarg):
return make_dsn(**kwargs)


class ConstrainedInt(int):
class ConstrainedMeta(type):
Copy link
Contributor

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?

@jaheba
Copy link
Contributor Author

jaheba commented Jun 7, 2018

Addressed all comments, I think.

@@ -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)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

remove

@jaheba
Copy link
Contributor Author

jaheba commented Jun 7, 2018 via email

@samuelcolvin samuelcolvin merged commit 3ef5955 into pydantic:master Jun 8, 2018
@samuelcolvin
Copy link
Member

great, thank you very much.

@jaheba jaheba deleted the inclusive_ranges branch June 8, 2018 10:01
alexdrydew pushed a commit to alexdrydew/pydantic that referenced this pull request Dec 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants