Skip to content

Commit 7356e10

Browse files
bpo-38557: Improve documentation for list and tuple C API. (GH-16925)
(cherry picked from commit d898d20) Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
1 parent 493fef6 commit 7356e10

File tree

3 files changed

+19
-12
lines changed

3 files changed

+19
-12
lines changed

Doc/c-api/list.rst

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -96,8 +96,9 @@ List Objects
9696
9797
.. c:function:: int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item)
9898
99-
Set the item at index *index* in list to *item*. Return ``0`` on success
100-
or ``-1`` on failure.
99+
Set the item at index *index* in list to *item*. Return ``0`` on success.
100+
If *index* is out of bounds, return ``-1`` and set an :exc:`IndexError`
101+
exception.
101102
102103
.. note::
103104
@@ -148,8 +149,7 @@ List Objects
148149
149150
Return a list of the objects in *list* containing the objects *between* *low*
150151
and *high*. Return *NULL* and set an exception if unsuccessful. Analogous
151-
to ``list[low:high]``. Negative indices, as when slicing from Python, are not
152-
supported.
152+
to ``list[low:high]``. Indexing from the end of the list is not supported.
153153
154154
.. versionchanged:: 2.5
155155
This function used an :c:type:`int` for *low* and *high*. This might
@@ -161,8 +161,8 @@ List Objects
161161
Set the slice of *list* between *low* and *high* to the contents of
162162
*itemlist*. Analogous to ``list[low:high] = itemlist``. The *itemlist* may
163163
be *NULL*, indicating the assignment of an empty list (slice deletion).
164-
Return ``0`` on success, ``-1`` on failure. Negative indices, as when
165-
slicing from Python, are not supported.
164+
Return ``0`` on success, ``-1`` on failure. Indexing from the end of the
165+
list is not supported.
166166
167167
.. versionchanged:: 2.5
168168
This function used an :c:type:`int` for *low* and *high*. This might

Doc/c-api/tuple.rst

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ Tuple Objects
8282
.. c:function:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
8383
8484
Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is
85-
out of bounds, return *NULL* and sets an :exc:`IndexError` exception.
85+
out of bounds, return *NULL* and set an :exc:`IndexError` exception.
8686
8787
.. versionchanged:: 2.5
8888
This function used an :c:type:`int` type for *pos*. This might require
@@ -100,8 +100,9 @@ Tuple Objects
100100
101101
.. c:function:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
102102
103-
Take a slice of the tuple pointed to by *p* from *low* to *high* and return it
104-
as a new tuple.
103+
Return the slice of the tuple pointed to by *p* between *low* and *high*,
104+
or *NULL* on failure. This is the equivalent of the Python expression
105+
``p[low:high]``. Indexing from the end of the list is not supported.
105106
106107
.. versionchanged:: 2.5
107108
This function used an :c:type:`int` type for *low* and *high*. This might
@@ -111,11 +112,13 @@ Tuple Objects
111112
.. c:function:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
112113
113114
Insert a reference to object *o* at position *pos* of the tuple pointed to by
114-
*p*. Return ``0`` on success.
115+
*p*. Return ``0`` on success. If *pos* is out of bounds, return ``-1``
116+
and set an :exc:`IndexError` exception.
115117
116118
.. note::
117119
118-
This function "steals" a reference to *o*.
120+
This function "steals" a reference to *o* and discards a reference to
121+
an item already in the tuple at the affected position.
119122
120123
.. versionchanged:: 2.5
121124
This function used an :c:type:`int` type for *pos*. This might require
@@ -129,7 +132,10 @@ Tuple Objects
129132
130133
.. note::
131134
132-
This function "steals" a reference to *o*.
135+
This macro "steals" a reference to *o*, and, unlike
136+
:c:func:`PyTuple_SetItem`, does *not* discard a reference to any item that
137+
is being replaced; any reference in the tuple at position *pos* will be
138+
leaked.
133139
134140
.. versionchanged:: 2.5
135141
This function used an :c:type:`int` type for *pos*. This might require

Doc/tools/susp-ignored.csv

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
c-api/arg,,:ref,"PyArg_ParseTuple(args, ""O|O:ref"", &object, &callback)"
22
c-api/list,,:high,list[low:high]
33
c-api/sequence,,:i2,o[i1:i2]
4+
c-api/tuple,,:high,p[low:high]
45
c-api/unicode,,:end,str[start:end]
56
distutils/setupscript,,::,
67
extending/embedding,,:numargs,"if(!PyArg_ParseTuple(args, "":numargs""))"

0 commit comments

Comments
 (0)