From 25c874a76736c3a00d372295beec8c71fb664c8a Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Mon, 1 Dec 2025 16:31:46 +0100 Subject: [PATCH] PEP 814: Type annotation --- peps/pep-0814.rst | 24 ++++++++++++++++++++++-- 1 file changed, 22 insertions(+), 2 deletions(-) diff --git a/peps/pep-0814.rst b/peps/pep-0814.rst index e6a2ad7d363..6023f261f3c 100644 --- a/peps/pep-0814.rst +++ b/peps/pep-0814.rst @@ -294,6 +294,10 @@ Replace ``dict`` with ``frozendict`` for constants: * ``tomllib._parser``: ``BASIC_STR_ESCAPE_REPLACEMENTS`` * ``typing``: ``_PROTO_ALLOWLIST`` +Accept ``frozendict`` type: + +* ``builtins``: ``eval()`` and ``exec()`` (*globals* argument) + Extension modules ----------------- @@ -403,10 +407,26 @@ Method to convert ``dict`` to ``frozendict`` -------------------------------------------- Different methods have been proposed to convert a mutable ``dict`` to an -immutable ``frozendict`` with *O*\ (1) complexity. +immutable ``frozendict`` with *O*\ (1) complexity, such as +``dict.freeze()``. The idea would be to move ``dict`` contents into +``frozendict``: it would make the ``dict`` empty. Another idea would be +to use "copy-on-write": only copy the ``dict`` at its first +modification. We consider that such method can be added later if needed, but it -doesn't have to be added right now. +doesn't have to be added right now. Moreover, if such method is added, +it would be nice to add a similar method for ``list``/``tuple`` and +``set``/``frozenset``. See also :pep:`351` (Freeze protocol). + +Type annotation +--------------- + +It `has been proposed +`__ +to add ``class TD(TypedDict, frozen=True)`` or ``Frozen[MyTypedDict]`` +to define a ``frozendict`` type. + +We consider that such type can be added later if needed. References