Skip to content

Commit 248af25

Browse files
miss-islingtonsobolevnerlend-aasland
authored
[3.12] gh-123254: Improve tuple C API docs with more info about errors (GH-123255) (#123415)
gh-123254: Improve `tuple` C API docs with more info about errors (GH-123255) (cherry picked from commit 6f563e3) Co-authored-by: sobolevn <[email protected]> Co-authored-by: Erlend E. Aasland <[email protected]>
1 parent 4deb32a commit 248af25

File tree

1 file changed

+16
-8
lines changed

1 file changed

+16
-8
lines changed

Doc/c-api/tuple.rst

+16-8
Original file line numberDiff line numberDiff line change
@@ -33,25 +33,27 @@ Tuple Objects
3333
3434
.. c:function:: PyObject* PyTuple_New(Py_ssize_t len)
3535
36-
Return a new tuple object of size *len*, or ``NULL`` on failure.
36+
Return a new tuple object of size *len*,
37+
or ``NULL`` with an exception set on failure.
3738
3839
3940
.. c:function:: PyObject* PyTuple_Pack(Py_ssize_t n, ...)
4041
41-
Return a new tuple object of size *n*, or ``NULL`` on failure. The tuple values
42+
Return a new tuple object of size *n*,
43+
or ``NULL`` with an exception set on failure. The tuple values
4244
are initialized to the subsequent *n* C arguments pointing to Python objects.
4345
``PyTuple_Pack(2, a, b)`` is equivalent to ``Py_BuildValue("(OO)", a, b)``.
4446
4547
4648
.. c:function:: Py_ssize_t PyTuple_Size(PyObject *p)
4749
4850
Take a pointer to a tuple object, and return the size of that tuple.
51+
On error, return ``-1`` and with an exception set.
4952
5053
5154
.. c:function:: Py_ssize_t PyTuple_GET_SIZE(PyObject *p)
5255
53-
Return the size of the tuple *p*, which must be non-``NULL`` and point to a tuple;
54-
no error checking is performed.
56+
Like :c:func:`PyTuple_Size`, but without error checking.
5557
5658
5759
.. c:function:: PyObject* PyTuple_GetItem(PyObject *p, Py_ssize_t pos)
@@ -74,8 +76,10 @@ Tuple Objects
7476
.. c:function:: PyObject* PyTuple_GetSlice(PyObject *p, Py_ssize_t low, Py_ssize_t high)
7577
7678
Return the slice of the tuple pointed to by *p* between *low* and *high*,
77-
or ``NULL`` on failure. This is the equivalent of the Python expression
78-
``p[low:high]``. Indexing from the end of the tuple is not supported.
79+
or ``NULL`` with an exception set on failure.
80+
81+
This is the equivalent of the Python expression ``p[low:high]``.
82+
Indexing from the end of the tuple is not supported.
7983
8084
8185
.. c:function:: int PyTuple_SetItem(PyObject *p, Py_ssize_t pos, PyObject *o)
@@ -132,6 +136,8 @@ type.
132136
Create a new struct sequence type from the data in *desc*, described below. Instances
133137
of the resulting type can be created with :c:func:`PyStructSequence_New`.
134138
139+
Return ``NULL`` with an exception set on failure.
140+
135141
136142
.. c:function:: void PyStructSequence_InitType(PyTypeObject *type, PyStructSequence_Desc *desc)
137143
@@ -140,8 +146,8 @@ type.
140146
141147
.. c:function:: int PyStructSequence_InitType2(PyTypeObject *type, PyStructSequence_Desc *desc)
142148
143-
The same as ``PyStructSequence_InitType``, but returns ``0`` on success and ``-1`` on
144-
failure.
149+
Like :c:func:`PyStructSequence_InitType`, but returns ``0`` on success
150+
and ``-1`` with an exception set on failure.
145151
146152
.. versionadded:: 3.4
147153
@@ -198,6 +204,8 @@ type.
198204
Creates an instance of *type*, which must have been created with
199205
:c:func:`PyStructSequence_NewType`.
200206
207+
Return ``NULL`` with an exception set on failure.
208+
201209
202210
.. c:function:: PyObject* PyStructSequence_GetItem(PyObject *p, Py_ssize_t pos)
203211

0 commit comments

Comments
 (0)