Skip to content

Commit cecf233

Browse files
gh-138098: Clarify strong references in PyDict_Next docs for free-threaded build
1 parent 3706ef6 commit cecf233

File tree

1 file changed

+8
-0
lines changed

1 file changed

+8
-0
lines changed

Doc/c-api/dict.rst

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -258,6 +258,14 @@ Dictionary Objects
258258
value represents offsets within the internal dictionary structure, and
259259
since the structure is sparse, the offsets are not consecutive.
260260
261+
.. note::
262+
263+
In the free-threaded build, this function can be used safely inside
264+
a critical section. However, the references returned for *pkey* and
265+
*pvalue* are borrowed and only valid while the critical section is
266+
held. If you need to use these objects outside the critical section,
267+
create strong references (for example, with :c:func:`Py_NewRef`).
268+
261269
For example::
262270
263271
PyObject *key, *value;

0 commit comments

Comments
 (0)