Thanks to visit codestin.com
Credit goes to github.com

Skip to content

gh-129567: Add a note to typing.TypedDict docs about name mangling #130233

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

Merged
merged 3 commits into from
Mar 4, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 6 additions & 1 deletion Doc/library/typing.rst
Original file line number Diff line number Diff line change
Expand Up @@ -2551,15 +2551,20 @@ types.

This functional syntax allows defining keys which are not valid
:ref:`identifiers <identifiers>`, for example because they are
keywords or contain hyphens::
keywords or contain hyphens, or when key names must not be
:ref:`mangled <private-name-mangling>` like regular private names::

# raises SyntaxError
class Point2D(TypedDict):
in: int # 'in' is a keyword
x-y: int # name with hyphens

class Definition(TypedDict):
__schema: str # mangled to `_Definition__schema`

# OK, functional syntax
Point2D = TypedDict('Point2D', {'in': int, 'x-y': int})
Definition = TypedDict('Definition', {'__schema': str}) # not mangled

By default, all keys must be present in a ``TypedDict``. It is possible to
mark individual keys as non-required using :data:`NotRequired`::
Expand Down
Loading