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
Import modules/objects directly from v1 namespace #9162
base: 1.10.X-fixes
Are you sure you want to change the base?
Conversation
This PR is ready for reviewing, please let me know if there are any other steps I can help out with here! Please review :) |
@PrettyWood is there anything else I need to do on my end on this PR? This is my first PR into pydantic so apologies if I've missed an automation somewhere! |
Great, thanks so much for your work! Apologies for the review delay - was focusing on FastUI for a bit. You've done everything perfectly here! |
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.
Great, thanks! We can release this with 1.10.16!
Working on getting the pipeline all green, will merge when that's done! |
Hmph, looks like tests are failing in some cases:
|
Thanks @sydney-runkle for looking through it! hmm weird, running locally all my tests pass, though perhaps I should exclude the mypy module from being imported directly in the import test, given that I get the feeling that the |
oh actually nevermind the
seems to do the trick. |
Hmph, looks like we're still getting some test failures. I'd be ok with a more minimal approach here - not testing Thanks! |
I'm not entirely sure there is a nice fix for the linux compiled tests to be honest - not one that I can think of at least :( (that doesn't involve converting all the relative imports in pydantic to absolute) - given it only raises an ImportWarning - and that this |
3bc7aa0
to
7a43881
Compare
Change Summary
Following on from this PR about adding a
v1.py
namespace to pydantic to better follow the v2 syntax of importing v1 objects, imports such as:or:
cannot be directly swapped for:
or:
imports. If this was the case, this would make unpinning from v1 --> v2 much simpler as a simple find and replace would be all that is needed to convert
from pydantic
-->from pydantic.v1
instead (ofc still using v1 types and models).One caveat with this approach is if this happens:
but ideally the import syntax should be changed across a codebase rather than only in some places. Note that anything in the
__init__.py
pydantic namespace is still imported wholesale:since these modules are imported directly from the underlying submodules. This also means that for the former import block, the
ModelField
in this case is imported twice.Additionally, things like
Pylance
can't directly resolve the import path forpydantic.v1.fields
imports using this syntax, but ideally that will be very transient since as soon as the find and replace is executed, anypydantic<2
pins should be able to be removed wholesale and the import will be resolved in pydantic v2.Checklist
Selected reviewer: @sydney-runkle
skip change file check
Fix #9357
Selected Reviewer: @PrettyWood