@@ -12,7 +12,7 @@ Abstract
1212A new public immutable type ``frozendict `` is added to the ``builtins ``
1313module.
1414
15- We expect frozendict to be safe by design, as it prevents any unintended
15+ We expect `` frozendict `` to be safe by design, as it prevents any unintended
1616modifications. This addition benefits not only CPython’s standard
1717library, but also third-party maintainers who can take advantage of a
1818reliable, immutable dictionary type.
@@ -34,18 +34,18 @@ desirable:
3434
3535* This hashable property permits functions decorated with
3636 ``@functools.lru_cache() `` to accept immutable mappings as arguments.
37- Unlike an immutable mapping, passing a plain dict to such a function
37+ Unlike an immutable mapping, passing a plain `` dict `` to such a function
3838 results in error.
3939
40- * Using an immutable mapping as a function parameter default value
40+ * Using an immutable mapping as a function parameter's default value
4141 avoids the problem of mutable default values.
4242
4343* Immutable mappings can be used to safely share dictionaries across
4444 thread and asynchronous task boundaries. The immutability makes it
4545 easier to reason about threads and asynchronous tasks.
4646
47- There are already multiple existing 3rd party ``frozendict `` and
48- `` frozenmap `` available on PyPI, proving that there is a need for
47+ There are already third- party ``frozendict `` and `` frozenmap `` packages
48+ available on PyPI, proving that there is demand for
4949immutable mappings.
5050
5151
@@ -60,9 +60,9 @@ module. It is not a ``dict`` subclass but inherits directly from
6060Construction
6161------------
6262
63- ``frozendict `` implements a dict-like construction API:
63+ ``frozendict `` implements a `` dict `` -like construction API:
6464
65- * ``frozendict() `` creates a new empty immutable mapping;
65+ * ``frozendict() `` creates a new empty immutable mapping.
6666
6767* ``frozendict(**kwargs) `` creates a mapping from ``**kwargs ``,
6868 e.g. ``frozendict(x=1, y=2) ``.
@@ -99,12 +99,12 @@ Hashing
9999 hash(frozendict(foo='bar')) # works
100100 hash(frozendict(foo=['a', 'b', 'c'])) # error, list is not hashable
101101
102- The hash value does not depend on the items order. It is computed on
102+ The hash value does not depend on the items' order. It is computed on
103103keys and values. Pseudo-code of ``hash(frozendict) ``::
104104
105105 hash(frozenset(frozendict.items()))
106106
107- Equality test does not depend on the items order neither. Example::
107+ Equality test does not depend on the items' order neither. Example::
108108
109109 >>> a = frozendict(x=1, y=2)
110110 >>> b = frozendict(y=2, x=1)
@@ -117,7 +117,7 @@ Equality test does not depend on the items order neither. Example::
117117Typing
118118------
119119
120- It is possible to use the standard typing notation for frozendicts ::
120+ It is possible to use the standard typing notation for `` frozendict `` \ s ::
121121
122122 m: frozendict[str, int] = frozendict(x=1)
123123
@@ -143,7 +143,7 @@ Add the following APIs:
143143* ``PyFrozenDict_CheckExact() `` macro
144144
145145Even if ``frozendict `` is not a ``dict `` subclass, it can be used with
146- ``PyDict_GetItemRef() `` and similiar "PyDict_Get" functions.
146+ ``PyDict_GetItemRef() `` and similar "PyDict_Get" functions.
147147
148148Passing a ``frozendict `` to ``PyDict_SetItem() `` or ``PyDict_DelItem() ``
149149fails with ``TypeError ``. ``PyDict_Check() `` on a ``frozendict `` is
@@ -156,8 +156,8 @@ containers to make thread-safe very easily. It will be important since
156156accepted, people need this for their migration.
157157
158158
159- Differences between dict and frozendict
160- =======================================
159+ Differences between `` dict `` and `` frozendict ``
160+ ===============================================
161161
162162* ``dict `` has more methods than ``frozendict ``:
163163
@@ -173,8 +173,8 @@ Differences between dict and frozendict
173173 and values can be hashed.
174174
175175
176- Possible candidates for frozendict in the stdlib
177- ================================================
176+ Possible candidates for `` frozendict `` in the stdlib
177+ ====================================================
178178
179179We have identified several stdlib modules where adopting ``frozendict ``
180180can enhance safety and prevent unintended modifications by design. We
@@ -233,16 +233,16 @@ Replace ``dict`` with ``frozendict`` for constants:
233233Relationship to PEP 416 frozendict
234234==================================
235235
236- Since 2012 (PEP 416), the Python ecosystem evolved:
236+ Since 2012 (:pep: ` 416 ` ), the Python ecosystem evolved:
237237
238238* ``asyncio `` was added in 2014 (Python 3.4)
239- * Free Threading was added in 2024 (Python 3.13)
239+ * Free threading was added in 2024 (Python 3.13)
240240* ``concurrent.interpreters `` was added in 2025 (Python 3.14)
241241
242242There are now more use cases to share immutable mappings.
243243
244244``frozendict `` now preserves the insertion order, whereas PEP 416
245- ``frozendict `` was unordered (as PEP 603 ``frozenmap ``). ``frozendict ``
245+ ``frozendict `` was unordered (as :pep: ` 603 ` ``frozenmap ``). ``frozendict ``
246246relies on the ``dict `` implementation which preserves the insertion
247247order since Python 3.6.
248248
@@ -268,12 +268,12 @@ Relationship to PEP 603 frozenmap
268268 * ``excluding(key) ``
269269 * ``union(mapping=None, **kw) ``
270270
271- ========== ============= ==============
272- Complexity ``frozenmap `` ``frozendict ``
273- ========== ============= ==============
274- Lookup O (log n ) O (1)
275- Copy O (1) O(n )
276- ========== ============= ==============
271+ ========== ============== ==============
272+ Complexity ``frozenmap `` ``frozendict ``
273+ ========== ============== ==============
274+ Lookup * O * \ (log * n * ) * O * \ (1)
275+ Copy * O * \ (1) * O * \ (* n * )
276+ ========== ============== ==============
277277
278278
279279Reference Implementation
@@ -319,8 +319,8 @@ If ``frozendict`` does not inherit from ``dict``, there is no such
319319issue.
320320
321321
322- New syntax for frozendict literals
323- ----------------------------------
322+ New syntax for `` frozendict `` literals
323+ --------------------------------------
324324
325325Various syntaxes have been proposed to write ``frozendict `` literals.
326326
@@ -337,7 +337,7 @@ References
337337Acknowledgements
338338================
339339
340- This PEP is based on prior work from Yury Selivanov (PEP 603).
340+ This PEP is based on prior work from Yury Selivanov (:pep: ` 603 ` ).
341341
342342
343343Copyright
0 commit comments