diff options
author | Victor Stinner <vstinner@python.org> | 2024-04-19 08:41:37 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-04-19 08:41:37 (GMT) |
commit | 4605a197bd84da1a232bd835d8e8e654f2fef220 (patch) | |
tree | b0902a964ac1b2c14daf6e0774467e4b49b7caba | |
parent | 7e6fa5fceddc3f4721c036116c7a11533c8b23b3 (diff) | |
download | cpython-4605a197bd84da1a232bd835d8e8e654f2fef220.zip cpython-4605a197bd84da1a232bd835d8e8e654f2fef220.tar.gz cpython-4605a197bd84da1a232bd835d8e8e654f2fef220.tar.bz2 |
gh-117518: Clarify PyTuple_GetItem() borrowed reference in the doc (GH-117920)
-rw-r--r-- | Doc/c-api/tuple.rst | 6 |
1 files changed, 6 insertions, 0 deletions
diff --git a/Doc/c-api/tuple.rst b/Doc/c-api/tuple.rst index b371056..0d68a36 100644 --- a/Doc/c-api/tuple.rst +++ b/Doc/c-api/tuple.rst @@ -59,6 +59,12 @@ Tuple Objects Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is negative or out of bounds, return ``NULL`` and set an :exc:`IndexError` exception. + The returned reference is borrowed from the tuple *p* + (that is: it is only valid as long as you hold a reference to *p*). + To get a :term:`strong reference`, use + :c:func:`Py_NewRef(PyTuple_GetItem(...)) <Py_NewRef>` + or :c:func:`PySequence_GetItem`. + .. c:function:: PyObject* PyTuple_GET_ITEM(PyObject *p, Py_ssize_t pos) |