Skip to content

Commit 418021e

Browse files
[3.13] gh-129567: Add a note to typing.TypedDict docs about name mangling (GH-130233) (#130841)
gh-129567: Add a note to `typing.TypedDict` docs about name mangling (GH-130233) (cherry picked from commit 63ffb40) Co-authored-by: sobolevn <mail@sobolevn.me>
1 parent 39dc7a1 commit 418021e

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

Doc/library/typing.rst

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2475,15 +2475,20 @@ types.
24752475

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

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

2486+
class Definition(TypedDict):
2487+
__schema: str # mangled to `_Definition__schema`
2488+
24852489
# OK, functional syntax
24862490
Point2D = TypedDict('Point2D', {'in': int, 'x-y': int})
2491+
Definition = TypedDict('Definition', {'__schema': str}) # not mangled
24872492

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

0 commit comments

Comments
 (0)