Title: Private names in the bases of a generic class nested in a class are not mangled · Issue #162574 · python/cpython · GitHub
Open Graph Title: Private names in the bases of a generic class nested in a class are not mangled · Issue #162574 · python/cpython
X Title: Private names in the bases of a generic class nested in a class are not mangled · Issue #162574 · python/cpython
Description: Bug report Bug description: In a class body, class Plain(__Base) finds the outer class's _Outer__Base, but with type parameters the same base is looked up unmangled: class Outer: __Base = dict class Plain(__Base): pass print(Plain.__base...
Open Graph Description: Bug report Bug description: In a class body, class Plain(__Base) finds the outer class's _Outer__Base, but with type parameters the same base is looked up unmangled: class Outer: __Base = dict clas...
X Description: Bug report Bug description: In a class body, class Plain(__Base) finds the outer class's _Outer__Base, but with type parameters the same base is looked up unmangled: class Outer: __Base = dict ...
Opengraph URL: https://github.com/python/cpython/issues/162574
X: @github
Domain: github.com
IPv4 address: 140.82.112.3
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Private names in the bases of a generic class nested in a class are not mangled","articleBody":"# Bug report\n\n### Bug description:\n\nIn a class body, `class Plain(__Base)` finds the outer class's `_Outer__Base`, but with type parameters the same base is looked up unmangled:\n\n```python\nclass Outer:\n __Base = dict\n class Plain(__Base): pass\n print(Plain.__bases__)\n try:\n class Generic[T](__Base): pass\n print(Generic.__bases__)\n except NameError as e:\n print(\"NameError:\", e)\n```\n\n```\n(\u003cclass 'dict'>,)\nNameError: name '__Base' is not defined\n```\n\n`__Base` occurs textually in the definition of `Outer`, so it's a private name of `Outer` ([Private name mangling](https://docs.python.org/dev/reference/expressions.html#private-name-mangling)), and adding `[T]` to the nested class shouldn't change how its bases resolve. Since gh-119311, `_Py_MaybeMangle` (`Python/symtable.c`) leaves every name in the type parameter scope of a generic class unmangled except the type parameters, so it is no longer mangled with the new class's name, but not with the enclosing class's either. The same happens for bounds and class keywords. I found it while writing a Lean spec of Python.\n\n### CPython versions tested on:\n\n3.15, CPython main branch\n\n### Operating systems tested on:\n\nLinux\n","author":{"url":"https://github.com/Robertboy18","@type":"Person","name":"Robertboy18"},"datePublished":"2026-11-24T17:33:49Z","url":"https://github.com/python/cpython/issues/162574"}
| react-profiling | 0 |
| react-import-map | react,react-dom,react-dom/client,react-dom/profiling,react-is,react/compiler-runtime,react/jsx-dev-runtime,react/jsx-runtime,scheduler@b8488ee2c322 |
| route-pattern | /_view_fragments/issues/show/:user_id/:repository/:id/issue_layout(.:format) |
| route-controller | voltron_issues_fragments |
| route-action | issue_layout |
| fetch-nonce | v2:d773bd6c-e0b2-68db-e6e6-f018e946d414 |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | A022:12B33:F98943:14B828D:6B064C02 |
| html-safe-nonce | 396babd96a782eb20e67553f32a7ea92867c565d1c16cc7255b13ba564e12ac5 |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJBMDIyOjEyQjMzOkY5ODk0MzoxNEI4MjhEOjZCMDY0QzAyIiwidmlzaXRvcl9pZCI6IjUzNTYwNzc4NDIwMjEzNzA4ODIiLCJyZWdpb25fZWRnZSI6ImlhZCIsInJlZ2lvbl9yZW5kZXIiOiJpYWQifQ== |
| visitor-hmac | 471b18ab8bfa0f7c26d41eeafccc0d7e12bb95a3024ae2be8e2b5a676158a8db |
| hovercard-subject-tag | issue:6587709221 |
| github-keyboard-shortcuts | repository,issues,copilot |
| google-site-verification | Apib7-x98H0j5cPqHWwSMm6dNU4GmODRoqxLiDzdx9I |
| octolytics-url | https://collector.github.com/github/collect |
| analytics-location | / |
| fb:app_id | 1401488693436528 |
| apple-itunes-app | app-id=1477376905, app-argument=https://github.com/_view_fragments/issues/show/python/cpython/162574/issue_layout |
| twitter:image | https://opengraph.githubassets.com/d32ab53159b9ddca9e4c7a916d9d9405ee1900680ada0e427b70bdc7edea9f01/python/cpython/issues/162574 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/d32ab53159b9ddca9e4c7a916d9d9405ee1900680ada0e427b70bdc7edea9f01/python/cpython/issues/162574 |
| og:image:alt | Bug report Bug description: In a class body, class Plain(__Base) finds the outer class's _Outer__Base, but with type parameters the same base is looked up unmangled: class Outer: __Base = dict clas... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | Robertboy18 |
| hostname | github.com |
| expected-hostname | github.com |
| None | 772b6997ca4daa0428dd49a25d76052e765555ae560fe9c88517eb828bbd861e |
| turbo-cache-control | no-preview |
| go-import | github.com/python/cpython git https://github.com/python/cpython.git |
| octolytics-dimension-user_id | 1525981 |
| octolytics-dimension-user_login | python |
| octolytics-dimension-repository_id | 81598961 |
| octolytics-dimension-repository_nwo | python/cpython |
| octolytics-dimension-repository_public | true |
| octolytics-dimension-repository_is_fork | false |
| octolytics-dimension-repository_network_root_id | 81598961 |
| octolytics-dimension-repository_network_root_nwo | python/cpython |
| turbo-body-classes | logged-out env-production page-responsive |
| disable-turbo | false |
| browser-stats-url | https://api.github.com/_private/browser/stats |
| browser-errors-url | https://api.github.com/_private/browser/errors |
| release | f1f9a08f7c769a37f1dfc18ad43d463c222a7eea |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
| Server | github.com |
| Content-Type | text/html; charset=utf-8 |
| Cache-Control | max-age=0, private, must-revalidate |
Viewport: width=device-width