Skip to content

Commit d4cc553

Browse files
authored
gh-141510: Update PyDict C API doc for frozendict (#145533)
Mention frozendict support.
1 parent 17eb035 commit d4cc553

File tree

1 file changed

+66
-1
lines changed

1 file changed

+66
-1
lines changed

Doc/c-api/dict.rst

Lines changed: 66 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,12 @@ Dictionary objects
4242
enforces read-only behavior. This is normally used to create a view to
4343
prevent modification of the dictionary for non-dynamic class types.
4444
45+
The first argument can be a :class:`dict`, a :class:`frozendict`, or a
46+
mapping.
47+
48+
.. versionchanged:: next
49+
Also accept :class:`frozendict`.
50+
4551
4652
.. c:var:: PyTypeObject PyDictProxy_Type
4753
@@ -68,15 +74,25 @@ Dictionary objects
6874
*key*, return ``1``, otherwise return ``0``. On error, return ``-1``.
6975
This is equivalent to the Python expression ``key in p``.
7076
77+
The first argument can be a :class:`dict` or a :class:`frozendict`.
78+
79+
.. versionchanged:: next
80+
Also accept :class:`frozendict`.
81+
7182
7283
.. c:function:: int PyDict_ContainsString(PyObject *p, const char *key)
7384
7485
This is the same as :c:func:`PyDict_Contains`, but *key* is specified as a
7586
:c:expr:`const char*` UTF-8 encoded bytes string, rather than a
7687
:c:expr:`PyObject*`.
7788
89+
The first argument can be a :class:`dict` or a :class:`frozendict`.
90+
7891
.. versionadded:: 3.13
7992
93+
.. versionchanged:: next
94+
Also accept :class:`frozendict`.
95+
8096
8197
.. c:function:: PyObject* PyDict_Copy(PyObject *p)
8298
@@ -122,8 +138,13 @@ Dictionary objects
122138
* If the key is missing, set *\*result* to ``NULL`` and return ``0``.
123139
* On error, raise an exception and return ``-1``.
124140
141+
The first argument can be a :class:`dict` or a :class:`frozendict`.
142+
125143
.. versionadded:: 3.13
126144
145+
.. versionchanged:: next
146+
Also accept :class:`frozendict`.
147+
127148
See also the :c:func:`PyObject_GetItem` function.
128149
129150
@@ -133,6 +154,8 @@ Dictionary objects
133154
has a key *key*. Return ``NULL`` if the key *key* is missing *without*
134155
setting an exception.
135156
157+
The first argument can be a :class:`dict` or a :class:`frozendict`.
158+
136159
.. note::
137160
138161
Exceptions that occur while this calls :meth:`~object.__hash__` and
@@ -143,6 +166,9 @@ Dictionary objects
143166
Calling this API without an :term:`attached thread state` had been allowed for historical
144167
reason. It is no longer allowed.
145168
169+
.. versionchanged:: next
170+
Also accept :class:`frozendict`.
171+
146172
147173
.. c:function:: PyObject* PyDict_GetItemWithError(PyObject *p, PyObject *key)
148174
@@ -151,6 +177,9 @@ Dictionary objects
151177
occurred. Return ``NULL`` **without** an exception set if the key
152178
wasn't present.
153179
180+
.. versionchanged:: next
181+
Also accept :class:`frozendict`.
182+
154183
155184
.. c:function:: PyObject* PyDict_GetItemString(PyObject *p, const char *key)
156185
@@ -166,6 +195,9 @@ Dictionary objects
166195
Prefer using the :c:func:`PyDict_GetItemWithError` function with your own
167196
:c:func:`PyUnicode_FromString` *key* instead.
168197
198+
.. versionchanged:: next
199+
Also accept :class:`frozendict`.
200+
169201
170202
.. c:function:: int PyDict_GetItemStringRef(PyObject *p, const char *key, PyObject **result)
171203
@@ -175,6 +207,9 @@ Dictionary objects
175207
176208
.. versionadded:: 3.13
177209
210+
.. versionchanged:: next
211+
Also accept :class:`frozendict`.
212+
178213
179214
.. c:function:: PyObject* PyDict_SetDefault(PyObject *p, PyObject *key, PyObject *defaultobj)
180215
@@ -238,17 +273,32 @@ Dictionary objects
238273
239274
Return a :c:type:`PyListObject` containing all the items from the dictionary.
240275
276+
The first argument can be a :class:`dict` or a :class:`frozendict`.
277+
278+
.. versionchanged:: next
279+
Also accept :class:`frozendict`.
280+
241281
242282
.. c:function:: PyObject* PyDict_Keys(PyObject *p)
243283
244284
Return a :c:type:`PyListObject` containing all the keys from the dictionary.
245285
286+
The first argument can be a :class:`dict` or a :class:`frozendict`.
287+
288+
.. versionchanged:: next
289+
Also accept :class:`frozendict`.
290+
246291
247292
.. c:function:: PyObject* PyDict_Values(PyObject *p)
248293
249294
Return a :c:type:`PyListObject` containing all the values from the dictionary
250295
*p*.
251296
297+
The first argument can be a :class:`dict` or a :class:`frozendict`.
298+
299+
.. versionchanged:: next
300+
Also accept :class:`frozendict`.
301+
252302
253303
.. c:function:: Py_ssize_t PyDict_Size(PyObject *p)
254304
@@ -257,11 +307,19 @@ Dictionary objects
257307
Return the number of items in the dictionary. This is equivalent to
258308
``len(p)`` on a dictionary.
259309
310+
The argument can be a :class:`dict` or a :class:`frozendict`.
311+
312+
.. versionchanged:: next
313+
Also accept :class:`frozendict`.
314+
260315
261316
.. c:function:: Py_ssize_t PyDict_GET_SIZE(PyObject *p)
262317
263318
Similar to :c:func:`PyDict_Size`, but without error checking.
264319
320+
.. versionchanged:: next
321+
Also accept :class:`frozendict`.
322+
265323
266324
.. c:function:: int PyDict_Next(PyObject *p, Py_ssize_t *ppos, PyObject **pkey, PyObject **pvalue)
267325
@@ -276,6 +334,8 @@ Dictionary objects
276334
value represents offsets within the internal dictionary structure, and
277335
since the structure is sparse, the offsets are not consecutive.
278336
337+
The first argument can be a :class:`dict` or a :class:`frozendict`.
338+
279339
For example::
280340
281341
PyObject *key, *value;
@@ -309,7 +369,7 @@ Dictionary objects
309369
}
310370
311371
The function is not thread-safe in the :term:`free-threaded <free threading>`
312-
build without external synchronization. You can use
372+
build without external synchronization for a mutable :class:`dict`. You can use
313373
:c:macro:`Py_BEGIN_CRITICAL_SECTION` to lock the dictionary while iterating
314374
over it::
315375
@@ -319,6 +379,8 @@ Dictionary objects
319379
}
320380
Py_END_CRITICAL_SECTION();
321381
382+
The function is thread-safe on a :class:`frozendict`.
383+
322384
.. note::
323385
324386
On the free-threaded build, this function can be used safely inside a
@@ -329,6 +391,9 @@ Dictionary objects
329391
:term:`strong reference <strong reference>` (for example, using
330392
:c:func:`Py_NewRef`).
331393
394+
.. versionchanged:: next
395+
Also accept :class:`frozendict`.
396+
332397
.. c:function:: int PyDict_Merge(PyObject *a, PyObject *b, int override)
333398
334399
Iterate over mapping object *b* adding key-value pairs to dictionary *a*.

0 commit comments

Comments
 (0)