-
-
Notifications
You must be signed in to change notification settings - Fork 1.8k
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
Updates type signature for Field() constructor #9484
Conversation
Replaces 'float' or 'int' in lt/gt/le/ge, multiple_of, min/max_length arguments with the appropriate Protocol from annotated_types.
fccf82f
to
afe67c0
Compare
CodSpeed Performance ReportMerging #9484 will not alter performanceComparing Summary
|
The only test failures look to be with an older version of mypy. Maybe it doesn't fully recognize the protocols from |
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.
pydantic/fields.py
Outdated
multiple_of: annotated_types.MultipleOf | None | ||
strict: bool | None | ||
min_length: int | None | ||
max_length: int | None | ||
min_length: annotated_types.MinLen | None | ||
max_length: annotated_types.MaxLen | None |
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.
For these, let's actually keep the original type (float
and int
) and add an additional union member as the annotated_types
type. Ex:
multiple_of: int | annotated_types.MultipleOf | None
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.
Thinking about this more, let's also add some tests accordingly, verifying that MultipleOf
works in this case (it might not, due to expectations on the pydantic-core
end of things.
@bjmc the But the |
@dmontagu Good shout, I'll revert those. |
I was overgeneralizing from the I suppose to be extremely pedantic, min/max lengths should be typed |
@sydney-runkle - Confirming this fixes my issue, using the same
|
Replaces
float
inlt
/gt
/le
/ge
, arguments with the appropriate Protocol fromannotated_types
.Change Summary
Related to #9472 updates the type signatures in
Field()
to be less restrictive, using the appropriate protocols fromannotated_types
instead of strictfloat
orint
types. This should be a nonbreaking change.Related issue number
fixes #9472
Checklist