Skip to content

Commit 15be34a

Browse files
[3.12] gh-117518: Clarify PyTuple_GetItem() borrowed reference in the doc (GH-117920) (#118087)
gh-117518: Clarify PyTuple_GetItem() borrowed reference in the doc (GH-117920) (cherry picked from commit 4605a19) Co-authored-by: Victor Stinner <[email protected]>
1 parent a0f82dd commit 15be34a

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

Doc/c-api/tuple.rst

+6
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,12 @@ Tuple Objects
5959
Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is
6060
negative or out of bounds, return ``NULL`` and set an :exc:`IndexError` exception.
6161
62+
The returned reference is borrowed from the tuple *p*
63+
(that is: it is only valid as long as you hold a reference to *p*).
64+
To get a :term:`strong reference`, use
65+
:c:func:`Py_NewRef(PyTuple_GetItem(...)) <Py_NewRef>`
66+
or :c:func:`PySequence_GetItem`.
67+
6268
6369
.. c:function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos)
6470

0 commit comments

Comments
 (0)