@@ -82,7 +82,7 @@ Tuple Objects
82
82
.. c :function :: PyObject* PyTuple_GetItem (PyObject *p, Py_ssize_t pos)
83
83
84
84
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.
86
86
87
87
.. versionchanged :: 2.5
88
88
This function used an :c:type: `int ` type for *pos *. This might require
@@ -100,8 +100,9 @@ Tuple Objects
100
100
101
101
.. c :function :: PyObject* PyTuple_GetSlice (PyObject *p, Py_ssize_t low, Py_ssize_t high)
102
102
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.
105
106
106
107
.. versionchanged :: 2.5
107
108
This function used an :c:type: `int ` type for *low * and *high *. This might
@@ -111,11 +112,13 @@ Tuple Objects
111
112
.. c :function :: int PyTuple_SetItem (PyObject *p, Py_ssize_t pos, PyObject *o)
112
113
113
114
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.
115
117
116
118
.. note ::
117
119
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.
119
122
120
123
.. versionchanged :: 2.5
121
124
This function used an :c:type: `int ` type for *pos *. This might require
@@ -129,7 +132,10 @@ Tuple Objects
129
132
130
133
.. note ::
131
134
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.
133
139
134
140
.. versionchanged :: 2.5
135
141
This function used an :c:type: `int ` type for *pos *. This might require
0 commit comments