-
-
Notifications
You must be signed in to change notification settings - Fork 31.4k
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
Inconsistent name mangling in TypedDict
in function and class forms
#129567
Labels
Comments
I'm +1 for documenting this and linking to the section about mangling so that users know how to write a mangling/demangling helper if needs arise (if they don't want to use the functional syntax) |
sobolevn
added a commit
to sobolevn/graphql-core
that referenced
this issue
Feb 16, 2025
`TypedDict` mangles private names as regular Python classes do. So, `__schema` name will become `_IntrospectionQuery__schema` instead. See python/cpython#129567 Found during python/mypy#16715
sobolevn
added a commit
to sobolevn/hydra-zen
that referenced
this issue
Feb 17, 2025
While working on python/mypy#16715 I've noticed that `_StoreCallSig` uses class form, while having `__kw` field. This field will be mangled. This is not something typing users want. See python/cpython#129567
sobolevn
added a commit
to sobolevn/cpython
that referenced
this issue
Feb 17, 2025
sobolevn
added a commit
that referenced
this issue
Mar 4, 2025
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this issue
Mar 4, 2025
…gling (pythonGH-130233) (cherry picked from commit 63ffb40) Co-authored-by: sobolevn <mail@sobolevn.me>
sobolevn
added a commit
to sobolevn/cpython
that referenced
this issue
Mar 4, 2025
sobolevn
added a commit
that referenced
this issue
Mar 4, 2025
This looks done :) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Bug report
Let's say that you have a dict like
{"__key": 1}
and you want to type it.You can write:
and:
Note that
A
mangles__key
as a regular name. WhileB
does not.I guess that it is expected, but!
Docs (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.We don't have explicit tests for this either.
And Typing Spec does not mention this as well: https://typing.readthedocs.io/en/latest/spec/typeddict.html
So, what we can do:
Please, share your thoughts on this. And I willing to send a PR with the fix.
Linked PRs
typing.TypedDict
docs about name mangling #130233typing.TypedDict
docs about name mangling (GH-130233) #130841The text was updated successfully, but these errors were encountered: