Skip to content

PEP 695: Name mangling leaks to surrounding scope #119395

Closed

Description

@JelleZijlstra

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

Activity

  1. added
    type-bugAn unexpected behavior, bug, or error
    interpreter-core(Objects, Python, Grammar, and Parser dirs)
    3.12only security fixes
    3.13only security fixes
    on May 22, 2024
  2. added a commit that references this issue on May 23, 2024
    a43da60
  3. added 2 commits that reference this issue on May 28, 2024
    a86d032
    2712e72
  4. added a commit that references this issue on May 28, 2024
    a9a74da
  5. added a commit that references this issue on May 28, 2024
    6394a72
  6. added a commit that references this issue on Jun 4, 2024
    dc40226
  7. added a commit that references this issue on Jul 17, 2024
    c16552f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

3.12only security fixes3.13only security fixes3.14bugs and security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or error

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions