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
Add mypy static checking for default and default_factory #3430
Add mypy static checking for default and default_factory #3430
Conversation
please review |
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.
Thank you, that's a great feature! I have some small concerns, but otherwise LGTM 🚀!
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.
LGTM, just a few changes.
please update. |
4098db8
to
9d3fed1
Compare
please review |
63f9d24
to
5342b83
Compare
62d6591
to
95f1ac8
Compare
95f1ac8
to
7a4b4a7
Compare
7a4b4a7
to
051dfc5
Compare
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.
LGTM
Thanks so much for this. |
Thank you for pydantic! This PR is quite old and the |
Thanks @klaa97, if we need to remove some older mypy that's fine, but we'll need to be explicit about which versions we support and which we drop. |
please update (just adding this so I keep track of which PRs I need to review). |
please review I should have fixed the tests, now it works also for mypy 0.910 (which had a few different way of handling things 😞 ). It also works with mypy 0.971, which is not currently tested in the CI. To check what is going to change validation-side in the plug-in, I think the best way is to check the |
Fixing coverage... Done! |
It is tested, it's run in the main test job of CI. |
thanks so much. |
Change Summary
This PR enhances the
mypy
Pydantic plugin to dynamically change the return type of theField
function, based on thedefault
anddefault_factory
arguments.Moreover, it adds an error in case the default and default_factory arguments are both specified.
The main goal is to enhance static checks, since they allow for a way more robust code and avoid runtime errors.
Suggestions on the
mypy
plugin APIs usage are welcome (documentation on that is not very big 😄)Related issue number
Fixes #3429
Checklist
changes/<pull request or issue id>-<github username>.md
file added describing change(see changes/README.md for details)