Add mypy static checking for default and default_factory#3430
Add mypy static checking for default and default_factory#3430samuelcolvin merged 11 commits intopydantic:masterfrom
Conversation
|
please review |
Bobronium
left a comment
There was a problem hiding this comment.
Thank you, that's a great feature! I have some small concerns, but otherwise LGTM 🚀!
samuelcolvin
left a comment
There was a problem hiding this comment.
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
|
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
mypyPydantic plugin to dynamically change the return type of theFieldfunction, based on thedefaultanddefault_factoryarguments.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
mypyplugin 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>.mdfile added describing change(see changes/README.md for details)