Skip to content

Commit 65bf6f5

Browse files
[3.14] gh-138098: Clarify strong references in PyDict_Next docs on the free-threaded build (GH-138106) (#138141)
Co-authored-by: PrinceNaroliya <[email protected]>
1 parent 86f7bb7 commit 65bf6f5

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

Doc/c-api/dict.rst

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -301,6 +301,15 @@ Dictionary Objects
301301
}
302302
Py_END_CRITICAL_SECTION();
303303
304+
.. note::
305+
306+
On the free-threaded build, this function can be used safely inside a
307+
critical section. However, the references returned for *pkey* and *pvalue*
308+
are :term:`borrowed <borrowed reference>` and are only valid while the
309+
critical section is held. If you need to use these objects outside the
310+
critical section or when the critical section can be suspended, create a
311+
:term:`strong reference <strong reference>` (for example, using
312+
:c:func:`Py_NewRef`).
304313
305314
.. c:function:: int PyDict_Merge(PyObject *a, PyObject *b, int override)
306315

0 commit comments

Comments
 (0)