Skip to content
Merged
Changes from 2 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
26 changes: 21 additions & 5 deletions Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,30 @@ raise :exc:`SyntaxError`).
:pep:`814`: Add frozendict built-in type
----------------------------------------

A new public immutable type :class:`frozendict` is added to the :mod:`builtins`
module. It is not a ``dict`` subclass but inherits directly from ``object``.

A ``frozendict`` can be hashed with ``hash(frozendict)`` if all keys and values
can be hashed.
A new public immutable type, :class:`frozendict`, is added to the :mod:`builtins` module.
It does not allow modification after creation. A ``frozendict`` is not a subclass of ``dict``;
it inherits directly from ``object``. A ``frozendict`` is hashable (i.e., ``hash(frozendict)`` works)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These lines should be wrapped.

as long as all of its keys and values are hashable.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, you may add that it preserves insertion order, but that comparison doesn't take the order in account (your example proves it).

>>> a = frozendict(x=1, y=2)
>>> a
frozendict({'x': 1, 'y': 2})
>>> a['z'] = 3
Traceback (most recent call last):
File "<python-input-2>", line 1, in <module>
a['z'] = 3
~^^^^^
TypeError: 'frozendict' object does not support item assignment
>>> b = frozendict(y=2, x=1)
>>> hash(a) == hash(b)
True
>>> a == b
True

.. seealso:: :pep:`814` for the full specification and rationale.

(Contributed by Victor Stinner and Donghee Na in :gh:`141510`.)


.. _whatsnew315-profiling-package:

Expand Down
Loading