-
-
Notifications
You must be signed in to change notification settings - Fork 2k
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 generic approach to strict type checking for constrained types #799
Merged
samuelcolvin
merged 14 commits into
pydantic:master
from
DerRidda:strict-constrained-types
Sep 17, 2019
Merged
Changes from 4 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
ed8c424
Added generic approach to strict type checking for constraint types
DerRidda 8ae5ec9
- Created StrictInt and StrictFloat subclasses and exported them
DerRidda fcb9a19
- Added section for Strict Types to docs
DerRidda ff89243
- Added changes file
DerRidda be04dcb
Update docs/index.rst
DerRidda b5da961
Update docs/index.rst
DerRidda e357d9f
- Create validators for strict int and float
DerRidda 5c9481b
Changed strict int and float tests to alos match for exception messag…
DerRidda 858c5d7
- Removed obvious note about lack of ConstrainedBool
DerRidda 1e88a10
Update pydantic/validators.py
DerRidda 29a53b0
- Removed StrictBool part from Boolean section of docs
DerRidda c2451b3
- Changed behavior of strictness for COnstrainedStr to match that fo …
DerRidda 408759d
- Actually make ConstrainedStr use the correct validator for strictness
DerRidda 359b468
Merge branch 'master' into strict-constrained-types
samuelcolvin File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
Added ability to validate strictness to ``ConstrainedFloat``, ``ConstrainedInt`` and ``ConstrainedStr`` and added | ||
``StrictFloat`` and ``StrictInt`` classes. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -785,6 +785,14 @@ The SecretStr and SecretBytes will be formatted as either `'**********'` or `''` | |
|
||
(This script is complete, it should run "as is") | ||
|
||
Strict Types | ||
............ | ||
|
||
You can use the ``StrictStr``, ``StrictInt`` and ``StrictFloat`` types to prevent coercion from compatible types. | ||
DerRidda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
These types will only pass validation when the validated value is of the respective type or is a subtype of that type. | ||
This behavior is also exposed via the ``strict`` field of the ``ConstrainedStr``, ``ConstrainedFloat`` and | ||
``ConstrainedInt`` classes and can be combined with a multitude of complex validation rules. | ||
DerRidda marked this conversation as resolved.
Show resolved
Hide resolved
DerRidda marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Would be good to add a code example demonstrating this behaviour. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done |
||
Json Type | ||
......... | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
can you move the "StrictBool" section into here.
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.
You still need to remove the "StrictBool" section: https://pydantic-docs.helpmanual.io/#strictbool
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.
Done.