Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Compute mangled fullnames properly for nested classes inside functions #4931

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
Apr 26, 2018

Conversation

msullivan
Copy link
Collaborator

This reverts #4927 and fixes the (a?) bug that it was working around.

Previously, mangled local fullnames were only computed if the class was directly inside a function, and not for nested classes inside a function.

@msullivan msullivan requested review from JukkaL and ilevkivskyi April 18, 2018 19:50
mypy/semanal.py Outdated
@@ -995,7 +995,7 @@ def setup_class_def_analysis(self, defn: ClassDef) -> None:
defn.info._fullname = defn.info.name()
if self.is_func_scope() or self.type:
kind = MDEF
if self.is_func_scope():
if self.is_nested_func_scope():
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I am not sure this is the right solution. The nested class is clearly an MDEF, but on the other hand all these kinds will be refactored soon, so maybe it is OK. @JukkaL what do you think?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to call these LDEFs, since these have access to the local variables of an enclosing function, which is the most important distinction for classes. Whether it's nested within a class or not is less important.

mypy/semanal.py Outdated
@@ -995,7 +995,7 @@ def setup_class_def_analysis(self, defn: ClassDef) -> None:
defn.info._fullname = defn.info.name()
if self.is_func_scope() or self.type:
kind = MDEF
if self.is_func_scope():
if self.is_nested_func_scope():
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's okay to call these LDEFs, since these have access to the local variables of an enclosing function, which is the most important distinction for classes. Whether it's nested within a class or not is less important.

mypy/semanal.py Outdated
@@ -3109,6 +3109,10 @@ def leave(self) -> None:
def is_func_scope(self) -> bool:
return self.locals[-1] is not None

# Are we underneath a function scope, even if we are in a nested class also
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Move the comment to a docstring.

mypy/semanal.py Outdated
@@ -3109,6 +3109,10 @@ def leave(self) -> None:
def is_func_scope(self) -> bool:
return self.locals[-1] is not None

# Are we underneath a function scope, even if we are in a nested class also
def is_nested_func_scope(self) -> bool:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I was a bit confused by the name. Maybe rename to is_nested_within_func_scope?

@JukkaL JukkaL merged commit 615fca4 into master Apr 26, 2018
@msullivan msullivan deleted the fullname-damage branch April 27, 2018 08:02
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.

3 participants