@@ -57,7 +57,7 @@ Tuple Objects
5757.. c :function :: PyObject* PyTuple_GetItem (PyObject *p, Py_ssize_t pos)
5858
5959 Return the object at position *pos * in the tuple pointed to by *p *. If *pos * is
60- out of bounds, return *NULL * and sets an :exc: `IndexError ` exception.
60+ out of bounds, return *NULL * and set an :exc: `IndexError ` exception.
6161
6262
6363.. c :function :: PyObject* PyTuple_GET_ITEM (PyObject *p, Py_ssize_t pos)
@@ -67,18 +67,21 @@ Tuple Objects
6767
6868.. c :function :: PyObject* PyTuple_GetSlice (PyObject *p, Py_ssize_t low, Py_ssize_t high)
6969
70- Take a slice of the tuple pointed to by *p * from *low * to *high * and return it
71- as a new tuple.
70+ Return the slice of the tuple pointed to by *p * between *low * and *high *,
71+ or *NULL * on failure. This is the equivalent of the Python expression
72+ ``p[low:high] ``. Indexing from the end of the list is not supported.
7273
7374
7475.. c :function :: int PyTuple_SetItem (PyObject *p, Py_ssize_t pos, PyObject *o)
7576
7677 Insert a reference to object *o * at position *pos * of the tuple pointed to by
77- *p *. Return ``0 `` on success.
78+ *p *. Return ``0 `` on success. If *pos * is out of bounds, return ``-1 ``
79+ and set an :exc: `IndexError ` exception.
7880
7981 .. note ::
8082
81- This function "steals" a reference to *o *.
83+ This function "steals" a reference to *o * and discards a reference to
84+ an item already in the tuple at the affected position.
8285
8386
8487.. c :function :: void PyTuple_SET_ITEM (PyObject *p, Py_ssize_t pos, PyObject *o)
@@ -88,7 +91,10 @@ Tuple Objects
8891
8992 .. note ::
9093
91- This function "steals" a reference to *o *.
94+ This macro "steals" a reference to *o *, and, unlike
95+ :c:func: `PyTuple_SetItem `, does *not * discard a reference to any item that
96+ is being replaced; any reference in the tuple at position *pos * will be
97+ leaked.
9298
9399
94100.. c :function :: int _PyTuple_Resize (PyObject **p, Py_ssize_t newsize)
0 commit comments