Skip to content

Commit 5e7c4e1

Browse files
Move PyDict_Next strong ref note closer to free-threading section
1 parent 597c0b5 commit 5e7c4e1

File tree

1 file changed

+9
-9
lines changed

1 file changed

+9
-9
lines changed

Doc/c-api/dict.rst

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -258,15 +258,6 @@ 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-
On the :term:`free threaded <free threading>` build, this function can be used safely inside
264-
a critical section. However, the references returned for *pkey* and
265-
*pvalue* are :term:`borrowed <borrowed reference>` and only valid while the critical section is
266-
held. If you need to use these objects outside the critical section or when the critical section
267-
can be suspended, create :term:`strong references <strong reference>` (for example, with
268-
:c:func:`Py_NewRef`).
269-
270261
For example::
271262
272263
PyObject *key, *value;
@@ -304,6 +295,15 @@ Dictionary Objects
304295
:c:macro:`Py_BEGIN_CRITICAL_SECTION` to lock the dictionary while iterating
305296
over it::
306297
298+
.. note::
299+
300+
On the :term:`free threaded <free threading>` build, this function can be used safely inside
301+
a critical section. However, the references returned for *pkey* and
302+
*pvalue* are :term:`borrowed <borrowed reference>` and only valid while the critical section is
303+
held. If you need to use these objects outside the critical section or when the critical section
304+
can be suspended, create :term:`strong references <strong reference>` (for example, with
305+
:c:func:`Py_NewRef`).
306+
307307
Py_BEGIN_CRITICAL_SECTION(self->dict);
308308
while (PyDict_Next(self->dict, &pos, &key, &value)) {
309309
...

0 commit comments

Comments
 (0)