Title: Inconsistent name mangling in `TypedDict` in function and class forms · Issue #129567 · python/cpython · GitHub
Open Graph Title: Inconsistent name mangling in `TypedDict` in function and class forms · Issue #129567 · python/cpython
X Title: Inconsistent name mangling in `TypedDict` in function and class forms · Issue #129567 · python/cpython
Description: Bug report Let's say that you have a dict like {"__key": 1} and you want to type it. You can write: >>> import typing >>> class A(typing.TypedDict): ... __key: int >>> A.__mutable_keys__ frozenset({'_A__key'}) and: >>> B = typing.TypedDi...
Open Graph Description: Bug report Let's say that you have a dict like {"__key": 1} and you want to type it. You can write: >>> import typing >>> class A(typing.TypedDict): ... __key: int >>> A.__mutable_keys__ frozenset(...
X Description: Bug report Let's say that you have a dict like {"__key": 1} and you want to type it. You can write: >>> import typing >>> class A(typing.TypedDict): ... __key: int &...
Opengraph URL: https://github.com/python/cpython/issues/129567
X: @github
Domain: github.com
{"@context":"https://schema.org","@type":"DiscussionForumPosting","headline":"Inconsistent name mangling in `TypedDict` in function and class forms","articleBody":"# Bug report\n\nLet's say that you have a dict like `{\"__key\": 1}` and you want to type it.\n\nYou can write:\n\n```python\n>>> import typing\n>>> class A(typing.TypedDict):\n... __key: int\n\n>>> A.__mutable_keys__\nfrozenset({'_A__key'})\n```\n\nand:\n\n```python\n>>> B = typing.TypedDict(\"B\", [(\"__key\", int)])\n>>> B.__mutable_keys__\nfrozenset({'__key'})\n```\n\nNote that `A` mangles `__key` as a regular name. While `B` does not.\n\nI guess that it is expected, but!\nDocs (https://docs.python.org/3/library/typing.html#typing.TypedDict) does not say anything about this behavior. We only mention that functional form should be used for invalid identifiers. But, `__key` is a valid indentifier.\nWe don't have explicit tests for this either.\nAnd Typing Spec does not mention this as well: https://typing.readthedocs.io/en/latest/spec/typeddict.html\n\n\nSo, what we can do:\n- Do not mangle names in this case (hard and problematic: it can break existing stuff)\n- Document and test current behavior (my vote)\n\nPlease, share your thoughts on this. And I willing to send a PR with the fix.\n\n\u003c!-- gh-linked-prs -->\n### Linked PRs\n* gh-130233\n* gh-130841\n* gh-130842\n\u003c!-- /gh-linked-prs -->\n","author":{"url":"https://github.com/sobolevn","@type":"Person","name":"sobolevn"},"datePublished":"2025-02-02T07:25:27Z","url":"https://github.com/python/cpython/issues/129567"}
| 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:2a7440dd-0c53-9292-782a-585397585c9d |
| current-catalog-service-hash | 81bb79d38c15960b92d99bca9288a9108c7a47b18f2423d0f6438c5b7bcd2114 |
| request-id | B310:3F9D33:288A71A:3729DE4:6B004793 |
| html-safe-nonce | 6fd4d058b3c6abb1d201821f291c0800d5461a0afad4904a0e04bdfad6f58e6f |
| visitor-payload | eyJyZWZlcnJlciI6IiIsInJlcXVlc3RfaWQiOiJCMzEwOjNGOUQzMzoyODhBNzFBOjM3MjlERTQ6NkIwMDQ3OTMiLCJ2aXNpdG9yX2lkIjoiNDg2MDMxNTI4NjA3NjY3MTg5MiIsInJlZ2lvbl9lZGdlIjoiaWFkIiwicmVnaW9uX3JlbmRlciI6ImlhZCJ9 |
| visitor-hmac | bd07fbb53eec89a86986cddd3d4679ee7182a6c843ead71cbb11fc8589cc967c |
| hovercard-subject-tag | issue:2825656643 |
| 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/129567/issue_layout |
| twitter:image | https://opengraph.githubassets.com/a012bbe38653732505fa1c134e0c0afe39e4dfe3f843f1657bb3e284af476a9f/python/cpython/issues/129567 |
| twitter:card | summary_large_image |
| og:image | https://opengraph.githubassets.com/a012bbe38653732505fa1c134e0c0afe39e4dfe3f843f1657bb3e284af476a9f/python/cpython/issues/129567 |
| og:image:alt | Bug report Let's say that you have a dict like {"__key": 1} and you want to type it. You can write: >>> import typing >>> class A(typing.TypedDict): ... __key: int >>> A.__mutable_keys__ frozenset(... |
| og:image:width | 1200 |
| og:image:height | 600 |
| og:site_name | GitHub |
| og:type | object |
| og:author:username | sobolevn |
| hostname | github.com |
| expected-hostname | github.com |
| None | 7d0829bbde9e48b2486cb5dd6d147896eb01d32134627091f818958a935ef3f0 |
| 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 | f3f3a43ca095cdea3abbb394112e971f9fdb94fa |
| ui-target | full |
| theme-color | #1e2327 |
| color-scheme | light dark |
| react-app-name | issues |
Links:
Viewport: width=device-width