-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Don't apply dataclass transform twice with plugin + mypy 1.1.1 #5162
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
Don't apply dataclass transform twice with plugin + mypy 1.1.1 #5162
Conversation
|
Would it be possible to add a test demonstrating the changed behavior? I recognize that we aren't actually running tests against 1.1.1 but I would still like to add some code that would be affected if we were (if only for future's sake). If such code already exists, I would appreciate if you could point me at it. If you aren't comfortable with the mypy plugin testing infrastructure, if you can just show me how to reproduce the issue that this resolves, that might be enough for me to add it to the tests. |
I guess we could add the from dataclasses import InitVar
from pydantic.dataclasses import dataclass
@dataclass
class MyDataClass:
foo: InitVar[str]
bar: str
MyDataClass(foo="foo", bar="bar")
Tbh I've ignored them so far as they take quite long to run. Additionally my laptop isn't that powerful. So I've only tested short examples to iterate on the correct fix. If you know a good place to add it, please feel free to do so. |
|
There's an issue with the added |
|
Just FYI -- I'm getting test failures on this branch with mypy 0.971. I'm thinking that needs to be resolved before merging. Specifically: Maybe this is just something weird with my local environment considering I don't see any reason this should be happening looking at your code. I fired off a CI run with the commit I pushed so we'll see if it all just passes... |
|
Seems to be some kind of real issue, unless I did something stupid without realizing it.. I'll look at this a bit later today if you don't get to it first @cdce8p |
|
Pushed some more changes. Should be ready now
|
|
I ran this in 1.1.1 and I didn't see the errors, so I'm going to merge. Thanks @cdce8p — I was going to say I wasn't able to get to this today, but great work figuring this all out, very much appreciated! |
|
Looks great, thank you both for sorting this. |
#5167) * Don't apply dataclass transform twice with plugin + mypy 1.1.1 (#5162) Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com> (cherry picked from commit 355e6da) * Stop handling fields without annotations * Drop reference to warn_untyped_fields config option for plugin * Arghhhhhh * Fix issue with running mypy test file in python 3.7 * Try again arrghhhh * Make work with new validator changes --------- Co-authored-by: David Montague <35119617+dmontagu@users.noreply.github.com>
Change Summary
Mypy
1.1.1added support for@dataclass_transform. With the plugin active, the mypy dataclass transformer would be executed twice. As the first iteration already removes theInitVarannotation, the second one results in an error message.The PR targets the
1.10.X-fixesbranch as that is much easier to test. If excepted, I'll also open a PR formain.Fixes: #5161
Checklist
changes/<pull request or issue id>-<github username>.mdfile added describing change(see changes/README.md for details)