@@ -57,7 +57,7 @@ Tuple Objects
57
57
.. c :function :: PyObject* PyTuple_GetItem (PyObject *p, Py_ssize_t pos)
58
58
59
59
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.
61
61
62
62
63
63
.. c :function :: PyObject* PyTuple_GET_ITEM (PyObject *p, Py_ssize_t pos)
@@ -67,18 +67,21 @@ Tuple Objects
67
67
68
68
.. c :function :: PyObject* PyTuple_GetSlice (PyObject *p, Py_ssize_t low, Py_ssize_t high)
69
69
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.
72
73
73
74
74
75
.. c :function :: int PyTuple_SetItem (PyObject *p, Py_ssize_t pos, PyObject *o)
75
76
76
77
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.
78
80
79
81
.. note ::
80
82
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.
82
85
83
86
84
87
.. c :function :: void PyTuple_SET_ITEM (PyObject *p, Py_ssize_t pos, PyObject *o)
@@ -88,7 +91,10 @@ Tuple Objects
88
91
89
92
.. note ::
90
93
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.
92
98
93
99
94
100
.. c :function :: int _PyTuple_Resize (PyObject **p, Py_ssize_t newsize)
0 commit comments