-
-
Notifications
You must be signed in to change notification settings - Fork 30.3k
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
Unexpected name mangling behavior with generics #119311
Comments
I agree this is a bug. We apply name mangling to all names that appear in the type parameter scope for the generic class (and also to all code after it, which is a separate bug: #119395). In the example, this means We could instead not do any mangling in the type parameter scope. That would fix this bug and simplify the code. However, it would break cases like this:
If we didn't do mangling in the type parameter scope, the second use of Fortunately, the set of names that can appear in a type parameter scope is very limited. I think it should be possible to mangle only the type parameter names defined in the scope but nothing else. This would make both my example and the OP's example work, but it adds some complexity to the symtable. |
…on#119464) Fixes python#119311. Fixes python#119395. (cherry picked from commit a9a74da)
python#119464) Fixes python#119311. Fixes python#119395. (cherry picked from commit a9a74da)
Add missing magic number 3571 for 3.13b1 It was added after branching in 6394a72#diff-efefe383b3a81d16150c280db0b64eed7569254299418f64cc0d749f8e16f3a4R475
Bug report
Bug description:
Name mangling behaves inconsistently when used with generics. Here’s the code to reproduce the issue:
This raises
NameError: name '_Bar__Foo' is not defined
. However, removing the[T]
results in the error disappearing. This suggests that the name mangling behavior is inconsistent when generics are involved. This behavior seems to be a bug, as it would be expected for the name mangling to either always occur or never occur, regardless of whether generics are used.CPython versions tested on:
3.12
Operating systems tested on:
Linux
Linked PRs
The text was updated successfully, but these errors were encountered: