https://github.com/python/cpython/commit/63ffb406bb000a42b0dbddcfc01cb98a12f8f76a commit: 63ffb406bb000a42b0dbddcfc01cb98a12f8f76a branch: main author: sobolevn <m...@sobolevn.me> committer: sobolevn <m...@sobolevn.me> date: 2025-03-04T18:15:00+03:00 summary:
gh-129567: Add a note to `typing.TypedDict` docs about name mangling (#130233) files: M Doc/library/typing.rst diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 0fee782121b0af..19b4081c993e44 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -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`:: _______________________________________________ Python-checkins mailing list -- python-checkins@python.org To unsubscribe send an email to python-checkins-le...@python.org https://mail.python.org/mailman3/lists/python-checkins.python.org/ Member address: arch...@mail-archive.com