mirror of
https://github.com/python/cpython.git
synced 2025-11-25 21:11:09 +00:00
gh-114329: Add PyList_GetItemRef function (GH-114504)
The new `PyList_GetItemRef` is similar to `PyList_GetItem`, but returns a strong reference instead of a borrowed reference. Additionally, if the passed "list" object is not a list, the function sets a `TypeError` instead of calling `PyErr_BadInternalCall()`.
This commit is contained in:
parent
0e71a295e9
commit
d0f1307580
12 changed files with 68 additions and 11 deletions
|
|
@ -56,13 +56,21 @@ List Objects
|
|||
Similar to :c:func:`PyList_Size`, but without error checking.
|
||||
|
||||
|
||||
.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
|
||||
.. c:function:: PyObject* PyList_GetItemRef(PyObject *list, Py_ssize_t index)
|
||||
|
||||
Return the object at position *index* in the list pointed to by *list*. The
|
||||
position must be non-negative; indexing from the end of the list is not
|
||||
supported. If *index* is out of bounds (<0 or >=len(list)),
|
||||
supported. If *index* is out of bounds (:code:`<0 or >=len(list)`),
|
||||
return ``NULL`` and set an :exc:`IndexError` exception.
|
||||
|
||||
.. versionadded:: 3.13
|
||||
|
||||
|
||||
.. c:function:: PyObject* PyList_GetItem(PyObject *list, Py_ssize_t index)
|
||||
|
||||
Like :c:func:`PyList_GetItemRef`, but returns a
|
||||
:term:`borrowed reference` instead of a :term:`strong reference`.
|
||||
|
||||
|
||||
.. c:function:: PyObject* PyList_GET_ITEM(PyObject *list, Py_ssize_t i)
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue