-
-
Notifications
You must be signed in to change notification settings - Fork 3k
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
Conversation
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(): |
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 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?
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'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(): |
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'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 |
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.
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: |
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 was a bit confused by the name. Maybe rename to is_nested_within_func_scope
?
8b6108c
to
2c4b60a
Compare
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.