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
mypy plugin working incorrectly for exported v1 module #6898
Comments
Great catch! @hramezani were you the one that set up the copying of the v1 code into the module? (Can't remember who it was..) Any ideas how to deal with this? Should we just manually edit it? It feels like that might be error prone in future releases... I guess we could write a v2 test that checks that the value is set properly in that module, so that we don't forget to fix it back up after re-updating the code. |
@JaimeLennox could you check whether the branch in #6921 fixes this issue for you? And if there are any other issues you can see how to fix, feel free to comment them on that PR. |
Yep, I can confirm with that branch it now works as expected - thanks for fixing! The only thing I'll mention is that there's now a user warning when mypy runs, which is a little strange given it comes from pydantic code itself, but I don't think it's a big deal given that users would be migrating away from the v1 plugin anyway:
|
@JaimeLennox we merged the relevant PRs into the with warnings.catch_warnings():
warnings.filterwarnings("ignore",category=UserWarning)
from pydantic.utils import ... # whatever the warning-generating import is The main reason not to do this is that it might make it a bit more likely that people use this approach up until the point where it actually breaks and have no warning about it. Given that, I'm not inclined to open the PR myself, but if you care enough to do so I would be inclined to merge it. Up to you. |
Initial Checks
Description
Hello! We're beginning our migration to pydantic v2, and as a first step we thought we'd simply upgrade the version and use the exported v1 module simply by changing
import pydantic
toimport pydantic.v1
in our imports.This works fine for the most part, but the mypy plugin doesn't seem to work anymore (note that we switched our mypy configuration to use
plugins = "pydantic.v1.mypy"
).This is most obvious with the v1
BaseSettings
class, where we load atrributes from a.env
file.For the example code below, running with pydantic v1 produces no errors, but pydantic v2 with the v1 mypy plugin shows:
I think this is probably because in the v1 mypy plugin, the fullname constants aren't using the v1 module?
E.g.
should probably be
?
Example Code
Python, Pydantic & OS Version
Selected Assignee: @dmontagu
The text was updated successfully, but these errors were encountered: