-
-
Notifications
You must be signed in to change notification settings - Fork 3k
New semantic analyzer: fix access to imported name in class body #6943
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
Conversation
We shouldn't use the line number of an imported name to decide whether it's defined when the line number refers to another file.
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.
Thanks! There are two comments, but feel free to address them in a separate PR.
mypy/newsemanal/semanal.py
Outdated
""" | ||
return (node is None | ||
or node.line < self.statement.line | ||
or not self.is_defined_in_current_module(node) |
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.
But what if the import happens after the point where imported name is used? Will it cause a false negative? If no, then I would add a test, otherwise maybe open a follow-up issue (or a TODO comment)?
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.
Added TODO comment. The problem seems minor enough that it's not worth creating an issue.
mypy/newsemanal/semanal.py
Outdated
or not self.is_defined_in_current_module(node) | ||
or isinstance(node, TypeInfo)) | ||
|
||
def is_defined_in_current_module(self, node: SymbolNode) -> bool: |
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.
It looks like this duplicates the functionality of is_local_name()
, should we just replace it? There is only one place where it is used in already_defined()
.
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 behavior is different for short names, but I updated is_local_name
to call this.
…hon#6943) We shouldn't use the line number of an imported name to decide whether it's defined when the line number refers to another file.
We shouldn't use the line number of an imported name to decide
whether it's defined when the line number refers to another
file.