From c322b6f82ae9643e9d66417ee3023d0f982ab314 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 19 Feb 2026 00:13:27 +0900 Subject: [PATCH 1/5] gh-141510: Update Whats News for frozzendict --- Doc/whatsnew/3.15.rst | 26 +++++++++++++++++++++----- 1 file changed, 21 insertions(+), 5 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 62ce7121424651..e0c250e36705e2 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -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`, has been 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) +as long as all of its keys and values are hashable. + +>>> a = frozendict(x=1, y=2) +>>> a +frozendict({'x': 1, 'y': 2}) +>>> a['z'] = 3 +Traceback (most recent call last): + File "", line 1, in + 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: From b4f2e18fa20f01ff971f081014d135e65567c2b1 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 19 Feb 2026 00:14:33 +0900 Subject: [PATCH 2/5] nit --- Doc/whatsnew/3.15.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index e0c250e36705e2..5fa767af132dad 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -188,7 +188,7 @@ raise :exc:`SyntaxError`). :pep:`814`: Add frozendict built-in type ---------------------------------------- -A new public immutable type, :class:`frozendict`, has been added to the :mod:`builtins` module. +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) as long as all of its keys and values are hashable. From df61c65d53d9104dc90d299d6e8f7701f125850a Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 19 Feb 2026 00:19:17 +0900 Subject: [PATCH 3/5] Update Doc/whatsnew/3.15.rst Co-authored-by: Victor Stinner --- Doc/whatsnew/3.15.rst | 30 ++++++++++++++++-------------- 1 file changed, 16 insertions(+), 14 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 5fa767af132dad..0110ae6c07ac2d 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -193,20 +193,22 @@ It does not allow modification after creation. A ``frozendict`` is not a subclas it inherits directly from ``object``. A ``frozendict`` is hashable (i.e., ``hash(frozendict)`` works) as long as all of its keys and values are hashable. ->>> a = frozendict(x=1, y=2) ->>> a -frozendict({'x': 1, 'y': 2}) ->>> a['z'] = 3 -Traceback (most recent call last): - File "", line 1, in - 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 +For example:: + + >>> a = frozendict(x=1, y=2) + >>> a + frozendict({'x': 1, 'y': 2}) + >>> a['z'] = 3 + Traceback (most recent call last): + File "", line 1, in + 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. From 857b4911163e06993a0174c33d7e92fe678dac0e Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 19 Feb 2026 07:56:05 +0900 Subject: [PATCH 4/5] Apply suggestions from code review Co-authored-by: Stan Ulbrych <89152624+StanFromIreland@users.noreply.github.com> --- Doc/whatsnew/3.15.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 0110ae6c07ac2d..1d8c3b6ba5d001 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -188,9 +188,9 @@ raise :exc:`SyntaxError`). :pep:`814`: Add frozendict built-in type ---------------------------------------- -A new public immutable type, :class:`frozendict`, is added to the :mod:`builtins` module. +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 hashable (i.e., ``hash(frozendict)`` works) +it inherits directly from ``object``. A ``frozendict`` is :term:`hashable` as long as all of its keys and values are hashable. For example:: From 20ab23df057889b66e4e9eec52b161397294a917 Mon Sep 17 00:00:00 2001 From: Donghee Na Date: Thu, 19 Feb 2026 21:42:35 +0900 Subject: [PATCH 5/5] What's news --- Doc/whatsnew/3.15.rst | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.15.rst b/Doc/whatsnew/3.15.rst index 1d8c3b6ba5d001..feccc496fad0e0 100644 --- a/Doc/whatsnew/3.15.rst +++ b/Doc/whatsnew/3.15.rst @@ -191,7 +191,8 @@ raise :exc:`SyntaxError`). 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. +as long as all of its keys and values are hashable. A ``frozendict`` preserves +insertion order, but comparison does not take order into account. For example::