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
Handle constraints being applied to schemas that don't accept it #6951
Merged
Merged
Changes from 10 commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
9d9a8f2
Handle constraints being applied to schemas that don't accept it
adriangb 6521e8c
Fix tests
adriangb 482b4ba
Allow ordering of constraints
adriangb f288e96
Fix type hint
adriangb c4ae580
Wip on fixing merging of FieldInfo and ordering of constraints
adriangb c44a7ed
Fix tests
dmontagu 5057f5f
Fix repr tests
adriangb 2e6d502
Add tests
adriangb 8504f52
Update pydantic/_internal/_known_annotated_metadata.py
adriangb 1eb0124
Fix test
adriangb de6eb9f
Update pydantic/_internal/_known_annotated_metadata.py
adriangb a096c14
Fix predicate error
adriangb b82b541
Fix test output
adriangb 2a88570
Fix test output
adriangb File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -5,6 +5,7 @@ | |
|
||
from __future__ import annotations as _annotations | ||
|
||
import math | ||
import re | ||
import typing | ||
from ipaddress import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network | ||
|
@@ -269,3 +270,9 @@ def max_length_validator(x: Any, max_length: Any) -> Any: | |
{'field_type': 'Value', 'max_length': max_length, 'actual_length': len(x)}, | ||
) | ||
return x | ||
|
||
|
||
def forbid_inf_nan_check(x: Any) -> Any: | ||
if not math.isfinite(x): | ||
raise PydanticKnownError('finite_number') | ||
return x | ||
Comment on lines
+275
to
+278
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. Added a test for the error case here |
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
Oops, something went wrong.
Oops, something went wrong.
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.
does this get called on
from pydantic import X
? If so we might need to worry about import time, if it's later/when require it shouldn't be a problem.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 believe it is imported immediately. It's not all that complex though, just assigning times to a dict. I could hide it behind an lru_cache function or something, but that would probably make schema generation slower (one more dict lookup), and that seems to be a bigger problem right now than import time