Skip to content

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

Merged
merged 3 commits into from
Jun 7, 2019

Conversation

JukkaL
Copy link
Collaborator

@JukkaL JukkaL commented Jun 6, 2019

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.

JukkaL added 2 commits June 6, 2019 14:59
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.
@JukkaL JukkaL requested a review from ilevkivskyi June 6, 2019 14:44
Copy link
Member

@ilevkivskyi ilevkivskyi left a 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.

"""
return (node is None
or node.line < self.statement.line
or not self.is_defined_in_current_module(node)
Copy link
Member

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)?

Copy link
Collaborator Author

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.

or not self.is_defined_in_current_module(node)
or isinstance(node, TypeInfo))

def is_defined_in_current_module(self, node: SymbolNode) -> bool:
Copy link
Member

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().

Copy link
Collaborator Author

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.

@JukkaL JukkaL merged commit 8127807 into master Jun 7, 2019
@gvanrossum gvanrossum deleted the semanal-class-body-fix branch June 17, 2019 18:33
PattenR pushed a commit to PattenR/mypy that referenced this pull request Jun 23, 2019
…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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants