-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
Fix module alias as instance attribute #8259
Conversation
mypy/semanal.py
Outdated
continue | ||
# respect explicitly annotated type | ||
if (isinstance(lval.node, Var) and lval.node.type is not None): | ||
continue | ||
lnode = self.current_symbol_table().get(lval.name) | ||
if lnode is None and self.type is not None: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The symbol table selection doesn't work correctly. In the case of the the self.<var> = x
definitions, the result of current_symbol_table
returns the warnings
variable the import
statement generated when run in the context of the __init__
function. But we actually want to have lnode = self.type.names.get(lval.name)
. Is there a better way to get the correct symbol table for the lval
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Would lval.node.info.names.get(lval.name)
be a better one?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I went to dive into this code to try to produce some guidance to give you, and it ended up being that approximately the minimal way for me to figure out what advice to give was to just go do it. (Though probably I /should/ have been able to figure it out looking at it, but...)
The issue was that the decision for which symbol table to look in needed to be made in a more principled way than "it wasn't present in the local table". Instead it needs to be made by actually checking whether it is a reference to self or not, so I went and did that.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LG! There are test failures however.
@msullivan Thanks! |
Fixes #4291
This is only a partial fix. As I'm new to the codebase, I'm unaware of the way an assignment correctly works. Thus also one of the newly added tests still fail. See the inline comment on the code change for the problem.