File tree Expand file tree Collapse file tree 1 file changed +21
-5
lines changed
Expand file tree Collapse file tree 1 file changed +21
-5
lines changed Original file line number Diff line number Diff line change @@ -188,14 +188,30 @@ raise :exc:`SyntaxError`).
188188:pep: `814 `: Add frozendict built-in type
189189----------------------------------------
190190
191- A new public immutable type :class: `frozendict ` is added to the :mod: `builtins `
192- module. It is not a ``dict `` subclass but inherits directly from ``object ``.
193-
194- A ``frozendict `` can be hashed with ``hash(frozendict) `` if all keys and values
195- can be hashed.
191+ A new public immutable type, :class: `frozendict `, has been added to the :mod: `builtins ` module.
192+ It does not allow modification after creation. A ``frozendict `` is not a subclass of ``dict ``;
193+ it inherits directly from ``object ``. A ``frozendict `` is hashable (i.e., ``hash(frozendict) `` works)
194+ as long as all of its keys and values are hashable.
195+
196+ >>> a = frozendict(x = 1 , y = 2 )
197+ >>> a
198+ frozendict({'x': 1, 'y': 2})
199+ >>> a[' z' ] = 3
200+ Traceback (most recent call last):
201+ File "<python-input-2>", line 1, in <module>
202+ a['z'] = 3
203+ ~^^^^^
204+ TypeError: 'frozendict' object does not support item assignment
205+ >>> b = frozendict(y = 2 , x = 1 )
206+ >>> hash (a) == hash (b)
207+ True
208+ >>> a == b
209+ True
196210
197211.. seealso :: :pep:`814` for the full specification and rationale.
198212
213+ (Contributed by Victor Stinner and Donghee Na in :gh: `141510 `.)
214+
199215
200216.. _whatsnew315-profiling-package :
201217
You can’t perform that action at this time.
0 commit comments