Skip to content

Commit da0dc71

Browse files
authored
PEP 814: Type annotation (#4721)
1 parent 35d9173 commit da0dc71

File tree

1 file changed

+22
-2
lines changed

1 file changed

+22
-2
lines changed

peps/pep-0814.rst

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,10 @@ Replace ``dict`` with ``frozendict`` for constants:
294294
* ``tomllib._parser``: ``BASIC_STR_ESCAPE_REPLACEMENTS``
295295
* ``typing``: ``_PROTO_ALLOWLIST``
296296

297+
Accept ``frozendict`` type:
298+
299+
* ``builtins``: ``eval()`` and ``exec()`` (*globals* argument)
300+
297301
Extension modules
298302
-----------------
299303

@@ -403,10 +407,26 @@ Method to convert ``dict`` to ``frozendict``
403407
--------------------------------------------
404408

405409
Different methods have been proposed to convert a mutable ``dict`` to an
406-
immutable ``frozendict`` with *O*\ (1) complexity.
410+
immutable ``frozendict`` with *O*\ (1) complexity, such as
411+
``dict.freeze()``. The idea would be to move ``dict`` contents into
412+
``frozendict``: it would make the ``dict`` empty. Another idea would be
413+
to use "copy-on-write": only copy the ``dict`` at its first
414+
modification.
407415

408416
We consider that such method can be added later if needed, but it
409-
doesn't have to be added right now.
417+
doesn't have to be added right now. Moreover, if such method is added,
418+
it would be nice to add a similar method for ``list``/``tuple`` and
419+
``set``/``frozenset``. See also :pep:`351` (Freeze protocol).
420+
421+
Type annotation
422+
---------------
423+
424+
It `has been proposed
425+
<https://discuss.python.org/t/pep-814-add-frozendict-built-in-type/104854/37>`__
426+
to add ``class TD(TypedDict, frozen=True)`` or ``Frozen[MyTypedDict]``
427+
to define a ``frozendict`` type.
428+
429+
We consider that such type can be added later if needed.
410430

411431

412432
References

0 commit comments

Comments
 (0)