-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
False positive: variable re-assigned with different type treated as of previous type #9700
Comments
Try using the |
Hmm, it works, thanks. The original error messages are a bit misleading though: most of the time the do not even point to redefinition problems Is this the indended behavior? Is it documented somewhere? |
The behavior when mypy does not always detect fields in the re-assigned type (sometimes it does, sometimes it does not) still looks like a bug to me. Have a look at the example with namedtuple |
@JelleZijlstra, could you re-open the issue? |
That's just because mypy keeps the original declared type. |
Then again: is it documented behavior or an implementation detail? I think it is very confusing and should be documented or fixed |
OK, let's reopen as a documentation issue. |
Bug Report
If you reassign a variable with a different (probably compatible) type, mypy still treats it as if it did not change the type
To Reproduce
Analyze this:
Expected Behavior
Actual Behavior
Your Environment
mypy.ini
(and other config files): default, freshly installedAdditional info
This version without classmethod constructor gives yet another error:
C
was originally a wrapper subclass of namedtuple, but I removed it while working on the MVE.One more example with namedtuple:
The text was updated successfully, but these errors were encountered: