-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Name resolution in mypy doesn't match Python #3775
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
Comments
Unfortunately, this is not an easy (and in fact old) problem. Mypy doesn't record the order of assignments (and other name bindings), so that while you are inside a class, then it finds y = x # no error here
x = 1 I am not sure whether we should keep this open or mark it as a duplicate of #2788 As a workaround, you can write |
Mypy could perhaps detect the issue and give a more informative error message, such as suggesting the |
@JukkaL I'm not sure if this is the same issue, but I'm seeing something similar for this example:
If this is related, then the error message might need to be more elaborate. |
@ns-cweber This is closely related. The problem is that mypy does not follow Python name resolution rules exactly one to one. There is no simple solution for this, but maybe indeed we could make the error message more clear. Anyway, I am raising priority to normal. |
the workaround suggested by @ilevkivskyi works for now well, with only the downside that people unfamiliar with the problem initially may wonder why we used the |
Raising priority to high since this keeps coming. We can at least try to follow Python rules in most cases. General solution may be hard. |
The original problem reported in this issue appears to no longer occur. |
Yup, this appears to have gotten fixed |
For example:
gives:
The text was updated successfully, but these errors were encountered: