You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
PEP 695: Name mangling leaks to surrounding scope #119395
% 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.
Activity
pythongh-119311: Fix name mangling with PEP 695 generic classes
pythongh-119311: Fix name mangling with PEP 695 generic classes (pyth…
[3.12] pythongh-119311: Fix name mangling with PEP 695 generic classes (
pythongh-119311: Fix name mangling with PEP 695 generic classes (pyth…
[3.13] gh-119311: Fix name mangling with PEP 695 generic classes (#11…
[3.12] gh-119311: Fix name mangling with PEP 695 generic classes (#11…
pythongh-119311: Fix name mangling with PEP 695 generic classes (pyth…