Skip to content

Commit ad1ef65

Browse files
vstinnerhugovk
andauthored
Apply suggestions from code review
Co-authored-by: Hugo van Kemenade <[email protected]>
1 parent fc4e926 commit ad1ef65

File tree

1 file changed

+27
-27
lines changed

1 file changed

+27
-27
lines changed

peps/pep-0814.rst

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ Abstract
1212
A new public immutable type ``frozendict`` is added to the ``builtins``
1313
module.
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
1616
modifications. This addition benefits not only CPython’s standard
1717
library, but also third-party maintainers who can take advantage of a
1818
reliable, 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
4949
immutable mappings.
5050

5151

@@ -60,9 +60,9 @@ module. It is not a ``dict`` subclass but inherits directly from
6060
Construction
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
103103
keys 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::
117117
Typing
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

145145
Even 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

148148
Passing a ``frozendict`` to ``PyDict_SetItem()`` or ``PyDict_DelItem()``
149149
fails with ``TypeError``. ``PyDict_Check()`` on a ``frozendict`` is
@@ -156,8 +156,8 @@ containers to make thread-safe very easily. It will be important since
156156
accepted, 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

179179
We have identified several stdlib modules where adopting ``frozendict``
180180
can enhance safety and prevent unintended modifications by design. We
@@ -233,16 +233,16 @@ Replace ``dict`` with ``frozendict`` for constants:
233233
Relationship 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

242242
There 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``
246246
relies on the ``dict`` implementation which preserves the insertion
247247
order 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

279279
Reference Implementation
@@ -319,8 +319,8 @@ If ``frozendict`` does not inherit from ``dict``, there is no such
319319
issue.
320320

321321

322-
New syntax for frozendict literals
323-
----------------------------------
322+
New syntax for ``frozendict`` literals
323+
--------------------------------------
324324

325325
Various syntaxes have been proposed to write ``frozendict`` literals.
326326

@@ -337,7 +337,7 @@ References
337337
Acknowledgements
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

343343
Copyright

0 commit comments

Comments
 (0)