]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-129567: Add a note to `typing.TypedDict` docs about name mangling (GH-13023...
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 4 Mar 2025 15:21:11 +0000 (16:21 +0100)
committerGitHub <noreply@github.com>
Tue, 4 Mar 2025 15:21:11 +0000 (15:21 +0000)
gh-129567: Add a note to `typing.TypedDict` docs about name mangling (GH-130233)
(cherry picked from commit 63ffb406bb000a42b0dbddcfc01cb98a12f8f76a)

Co-authored-by: sobolevn <mail@sobolevn.me>
Doc/library/typing.rst

index 0c45c21841ace4a3a9c8c8f463c509cb85432a15..bd6a793b88234b2e50c8133d17c49af3af0a54d0 100644 (file)
@@ -2475,15 +2475,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`::