diff options
author | Miss Skeleton (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-10-26 20:04:13 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-10-26 20:04:13 (GMT) |
commit | 7356e10820b160d14b0ce0aba5427a8f9e757aa7 (patch) | |
tree | 43af1f01398df8fc657dd3f5fcd8c0e8a6431328 | |
parent | 493fef60a7600f83fe6916ed89d0fb0c0aab484d (diff) | |
download | cpython-7356e10820b160d14b0ce0aba5427a8f9e757aa7.zip cpython-7356e10820b160d14b0ce0aba5427a8f9e757aa7.tar.gz cpython-7356e10820b160d14b0ce0aba5427a8f9e757aa7.tar.bz2 |
bpo-38557: Improve documentation for list and tuple C API. (GH-16925)
(cherry picked from commit d898d20e8c228229eb68e545f544db13f246f216)
Co-authored-by: Serhiy Storchaka <storchaka@gmail.com>
-rw-r--r-- | Doc/c-api/list.rst | 12 | ||||
-rw-r--r-- | Doc/c-api/tuple.rst | 18 | ||||
-rw-r--r-- | Doc/tools/susp-ignored.csv | 1 |
3 files changed, 19 insertions, 12 deletions
diff --git a/Doc/c-api/list.rst b/Doc/c-api/list.rst index a5e4a45..c28d6b0 100644 --- a/Doc/c-api/list.rst +++ b/Doc/c-api/list.rst @@ -96,8 +96,9 @@ List Objects .. c:function:: int PyList_SetItem(PyObject *list, Py_ssize_t index, PyObject *item) - Set the item at index *index* in list to *item*. Return ``0`` on success - or ``-1`` on failure. + Set the item at index *index* in list to *item*. Return ``0`` on success. + If *index* is out of bounds, return ``-1`` and set an :exc:`IndexError` + exception. .. note:: @@ -148,8 +149,7 @@ List Objects Return a list of the objects in *list* containing the objects *between* *low* and *high*. Return *NULL* and set an exception if unsuccessful. Analogous - to ``list[low:high]``. Negative indices, as when slicing from Python, are not - supported. + to ``list[low:high]``. Indexing from the end of the list is not supported. .. versionchanged:: 2.5 This function used an :c:type:`int` for *low* and *high*. This might @@ -161,8 +161,8 @@ List Objects Set the slice of *list* between *low* and *high* to the contents of *itemlist*. Analogous to ``list[low:high] = itemlist``. The *itemlist* may be *NULL*, indicating the assignment of an empty list (slice deletion). - Return ``0`` on success, ``-1`` on failure. Negative indices, as when - slicing from Python, are not supported. + Return ``0`` on success, ``-1`` on failure. Indexing from the end of the + list is not supported. .. versionchanged:: 2.5 This function used an :c:type:`int` for *low* and *high*. This might diff --git a/Doc/c-api/tuple.rst b/Doc/c-api/tuple.rst index 16de45f..fd85663 100644 --- a/Doc/c-api/tuple.rst +++ b/Doc/c-api/tuple.rst @@ -82,7 +82,7 @@ Tuple Objects .. c:function:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos) Return the object at position *pos* in the tuple pointed to by *p*. If *pos* is - out of bounds, return *NULL* and sets an :exc:`IndexError` exception. + out of bounds, return *NULL* and set an :exc:`IndexError` exception. .. versionchanged:: 2.5 This function used an :c:type:`int` type for *pos*. This might require @@ -100,8 +100,9 @@ Tuple Objects .. c:function:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high) - Take a slice of the tuple pointed to by *p* from *low* to *high* and return it - as a new tuple. + Return the slice of the tuple pointed to by *p* between *low* and *high*, + or *NULL* on failure. This is the equivalent of the Python expression + ``p[low:high]``. Indexing from the end of the list is not supported. .. versionchanged:: 2.5 This function used an :c:type:`int` type for *low* and *high*. This might @@ -111,11 +112,13 @@ Tuple Objects .. c:function:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o) Insert a reference to object *o* at position *pos* of the tuple pointed to by - *p*. Return ``0`` on success. + *p*. Return ``0`` on success. If *pos* is out of bounds, return ``-1`` + and set an :exc:`IndexError` exception. .. note:: - This function "steals" a reference to *o*. + This function "steals" a reference to *o* and discards a reference to + an item already in the tuple at the affected position. .. versionchanged:: 2.5 This function used an :c:type:`int` type for *pos*. This might require @@ -129,7 +132,10 @@ Tuple Objects .. note:: - This function "steals" a reference to *o*. + This macro "steals" a reference to *o*, and, unlike + :c:func:`PyTuple_SetItem`, does *not* discard a reference to any item that + is being replaced; any reference in the tuple at position *pos* will be + leaked. .. versionchanged:: 2.5 This function used an :c:type:`int` type for *pos*. This might require diff --git a/Doc/tools/susp-ignored.csv b/Doc/tools/susp-ignored.csv index f7d23e2..0efbbab 100644 --- a/Doc/tools/susp-ignored.csv +++ b/Doc/tools/susp-ignored.csv @@ -1,6 +1,7 @@ c-api/arg,,:ref,"PyArg_ParseTuple(args, ""O|O:ref"", &object, &callback)" c-api/list,,:high,list[low:high] c-api/sequence,,:i2,o[i1:i2] +c-api/tuple,,:high,p[low:high] c-api/unicode,,:end,str[start:end] distutils/setupscript,,::, extending/embedding,,:numargs,"if(!PyArg_ParseTuple(args, "":numargs""))" |