@@ -109,6 +109,46 @@ keys of a dict, for example:
109109 >>> collections.Counter(titles)
110110 Counter({'Lists': 2, 'Data types': 1, 'Sets': 1})
111111
112+ .. _frozendict :
113+
114+ ``frozendict ``
115+ --------------
116+
117+ .. versionadded :: 3.15
118+
119+ :pep: `814 ` introduces :class: `python3:frozendict `, an :term: `immutable `
120+ dictionary:
121+
122+ .. code-block :: pycon
123+
124+ >>> titles = frozendict({7.0: "Data Types", 7.1: "Lists", 7.2: "Tuples"})
125+ >>> titles
126+ frozendict({7.0: 'Data Types', 7.1: 'Lists', 7.2: 'Tuples'})
127+ >>> titles[7.3] = "Sets"
128+ Traceback (most recent call last):
129+ File "<python-input-16>", line 1, in <module>
130+ titles[7.3] = "Sets"
131+ ~~~~~~^^^^^
132+ TypeError: 'frozendict' object does not support item assignment
133+
134+ Immutable mappings are hashable, which means they can be used as keys in
135+ dictionaries, as elements in :doc: `sets <sequences-sets/sets >`, or accepted
136+ as arguments by functions :doc: `decorated <../functions/decorators >` with
137+ :func: `@functools.lru_cache `:
138+
139+ .. code-block :: pycon
140+
141+ >>> hash(titles)
142+ 3827265406416199624
143+
144+ The merge operator (``| ``) can be used to merge two ``frozendict `` objects or
145+ a ``frozendict `` object with a ``dict `` object, for example:
146+
147+ .. code-block :: pycon
148+
149+ >>> titles | new_titles
150+ frozendict({7.0: 'Data types', 7.1: 'Lists', 7.2: 'Tuples', 7.3: 'Sets'})
151+
112152 Extensions
113153----------
114154
0 commit comments