Skip to content
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
24 changes: 22 additions & 2 deletions peps/pep-0814.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
-----------------

Expand Down Expand Up @@ -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
<https://discuss.python.org/t/pep-814-add-frozendict-built-in-type/104854/37>`__
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
Expand Down