Skip to content
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

PEP 695: Name mangling leaks to surrounding scope #119395

Closed
JelleZijlstra opened this issue May 22, 2024 · 0 comments · Fixed by #119464
Closed

PEP 695: Name mangling leaks to surrounding scope #119395

JelleZijlstra opened this issue May 22, 2024 · 0 comments · Fixed by #119464
Assignees
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error

Comments

@JelleZijlstra
Copy link
Member

JelleZijlstra commented May 22, 2024

Bug report

% cat leak.py 
def f():
    __foo = 1
    class X[T]: ...
    return __foo
f()
% python3.12 leak.py
Traceback (most recent call last):
  File "/Users/jelle/py/cpython/leak.py", line 5, in <module>
    f()
  File "/Users/jelle/py/cpython/leak.py", line 4, in f
    return __foo
           ^^^^^
NameError: name '_X__foo' is not defined. Did you mean: '__foo'?

The PEP 695 implementation of generic classes turns on name mangling for the type parameter scope, but never turns it off afterwards. As a result, all code that appears syntactically after the PEP 695 scope also gets mangling applied to it.

I have a fix for this, but I believe applying it requires updating the magic number, and I'm not sure we can afford to to do that on the 3.12 branch.

Linked PRs

@JelleZijlstra JelleZijlstra added type-bug An unexpected behavior, bug, or error interpreter-core (Objects, Python, Grammar, and Parser dirs) 3.12 bugs and security fixes 3.13 bugs and security fixes labels May 22, 2024
@Eclips4 Eclips4 added the 3.14 new features, bugs and security fixes label May 22, 2024
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue May 23, 2024
@JelleZijlstra JelleZijlstra self-assigned this May 23, 2024
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue May 28, 2024
JelleZijlstra added a commit to JelleZijlstra/cpython that referenced this issue May 28, 2024
JelleZijlstra added a commit that referenced this issue May 28, 2024
Yhg1s pushed a commit that referenced this issue Jun 4, 2024
…9464) (#119644)

* [3.12] gh-119311: Fix name mangling with PEP 695 generic classes (#119464)

Fixes #119311. Fixes #119395.

(cherry picked from commit a9a74da)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
3.12 bugs and security fixes 3.13 bugs and security fixes 3.14 new features, bugs and security fixes interpreter-core (Objects, Python, Grammar, and Parser dirs) type-bug An unexpected behavior, bug, or error
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants