-
-
Notifications
You must be signed in to change notification settings - Fork 3k
Bug: raising a nested error class causes spurious ‘member is not assignable’ error #1968
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
Thanks for the bug report. There's one more variant that you didn't try -- I understand that that's just a work-around, and mypy really should handle such scoping issues better. Unfortunately, internally class definitions are treated quite specially, and there is also occasionally some confusion between instance and class attributes. So it may be a while before we get to fixing this. (If you want to give it a try please do, but be aware that this part of the mypy code is quite intricate, so I won't hold it against you if you pass.) |
The
I'll try to have a look at the code; we'll see how far I get. I am quite tentative, so anybody else should also feel free to pick this up, and not wait until/whether I report back. |
Great! Will be glad to see a fix if you can make one. If nothing else it would also be useful just to give it a better error message -- that error message is confusing and erroneous, in addition to this situation probably not being something that should be an error. |
I can't seem to reproduce the issue:
|
As of 0.511 it was still causing errors. I believe this was fixed in #3636. |
First off, thank you all for the delightful mypy tool. I really enjoy it every day I use it. ^_^
As for the bug report, mypy gives a spurious error in this scenario:
I have a class
Shift
with, nested inside it, the exception classShift.AlreadyCovered
. TheShift.cover()
method, which is annotated toreturn None, will
raise self.AlreadyCovered
under certain circumstances. Amypy
check then complains thatMember "AlreadyCovered" is not assignable
.See
cover1
in the example below.Mypy does not give an error in these variants:
cover2
)cover3
)reference defined inside the current class. (
cover4
)Minimal example of the error:
The variants that don't raise errors:
The text was updated successfully, but these errors were encountered: