-
-
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
Type signature for Field() gt/lt/gte/lte validators should include timedelta #9472
Comments
I'm not a typing wizard, but I wonder if a good resolution here would be to use the comparison protocols defined by typeshed for these field validators? I'm happy to open an PR if people like that approach, or have another suggestion. |
Hmm, I'm intrigued - feel free to open a PR and I can review. I don think it could be good to offer more general support here! |
Seems reasonable to use the comparison protocols, internally Pydantic uses the functions defined in Two options here:
|
Let's go with the |
I agree that |
@sydney-runkle I've got a draft PR up. I'm not quite sure where to add a test for this, since it's only a type-checking issue. Suggestions? |
Perhaps you could just add a before / after example to this PR running pyright on a file that uses a Update: I've added some notes to your PR re testing + some change requests! |
Initial Checks
Description
The type signature for the numeric min/max value constraints on Field() (i.e.
gt
,lt
,gte
,lte
) specified here is too restrictive, allowing onlyfloat
orNone
.In actual use, the validation works correctly as expected with
timedelta()
instances, but static type checkers (at least Pyright) object.Example Code
Python, Pydantic & OS Version
The text was updated successfully, but these errors were encountered: