Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings
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
29 changes: 24 additions & 5 deletions 29 Doc/whatsnew/3.15.rst
Original file line number Diff line number Diff line change
Expand Up @@ -188,14 +188,33 @@ 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 :term:`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 :term:`hashable`
as long as all of its keys and values are hashable. A ``frozendict`` preserves
insertion order, but comparison does not take order into account.

Copy link
Copy Markdown
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).

For example::

>>> 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
Morty Proxy This is a proxified and sanitized view of the page, visit original site.