Skip to content

Fix crash on access to local classes#2855

Merged
JukkaL merged 2 commits into
python:masterfrom
ilevkivskyi:crash-inner-class
Feb 27, 2017
Merged

Fix crash on access to local classes#2855
JukkaL merged 2 commits into
python:masterfrom
ilevkivskyi:crash-inner-class

Conversation

@ilevkivskyi
Copy link
Copy Markdown
Member

@ilevkivskyi ilevkivskyi commented Feb 12, 2017

Fixes #2559

The idea is the same as in PR #2553. The only difference is that mangled names are always stored in globals, otherwise there would be a problem for a method in a nested class that is itself inside a method.

@ilevkivskyi
Copy link
Copy Markdown
Member Author

@gvanrossum If you are curious, this monster still crashes when imported from elsewhere in incremental mode:

from typing import NamedTuple

class C:
    def f(self) -> None:
        class D:
            class E:
                def g(self) -> None:
                    A = NamedTuple('A', [('x', int), ('y', int)])
                    self.a = A(1, 1)
        self.c = D.E().a

This is why I made this PR to always use globals. Such approach is more robust against such deeply nested classes. In addition, always using globals simplifies code without risk of conflicts (since line numbers are unique anyway).

@JukkaL JukkaL merged commit ef6f156 into python:master Feb 27, 2017
@JukkaL
Copy link
Copy Markdown
Collaborator

JukkaL commented Feb 27, 2017

Thanks for the fix!

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