Skip to content

Commit bcf1c70

Browse files
miss-islingtonsobolevnskirpichevencukou
authored
[3.13] gh-121834: Improve complex C-API docs (GH-121835) (#121895)
gh-121834: Improve `complex` C-API docs (GH-121835) (cherry picked from commit 72dccd6) Co-authored-by: sobolevn <[email protected]> Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Petr Viktorin <[email protected]>
1 parent 96c524c commit bcf1c70

File tree

1 file changed

+22
-9
lines changed

1 file changed

+22
-9
lines changed

Doc/c-api/complex.rst

+22-9
Original file line numberDiff line numberDiff line change
@@ -25,12 +25,16 @@ pointers. This is consistent throughout the API.
2525
2626
The C structure which corresponds to the value portion of a Python complex
2727
number object. Most of the functions for dealing with complex number objects
28-
use structures of this type as input or output values, as appropriate. It is
29-
defined as::
28+
use structures of this type as input or output values, as appropriate.
29+
30+
.. c:member:: double real
31+
double imag
32+
33+
The structure is defined as::
3034

3135
typedef struct {
32-
double real;
33-
double imag;
36+
double real;
37+
double imag;
3438
} Py_complex;
3539

3640

@@ -106,11 +110,13 @@ Complex Numbers as Python Objects
106110
.. c:function:: PyObject* PyComplex_FromCComplex(Py_complex v)
107111
108112
Create a new Python complex number object from a C :c:type:`Py_complex` value.
113+
Return ``NULL`` with an exception set on error.
109114
110115
111116
.. c:function:: PyObject* PyComplex_FromDoubles(double real, double imag)
112117
113118
Return a new :c:type:`PyComplexObject` object from *real* and *imag*.
119+
Return ``NULL`` with an exception set on error.
114120
115121
116122
.. c:function:: double PyComplex_RealAsDouble(PyObject *op)
@@ -121,7 +127,9 @@ Complex Numbers as Python Objects
121127
:meth:`~object.__complex__` method, this method will first be called to
122128
convert *op* to a Python complex number object. If :meth:`!__complex__` is
123129
not defined then it falls back to call :c:func:`PyFloat_AsDouble` and
124-
returns its result. Upon failure, this method returns ``-1.0``, so one
130+
returns its result.
131+
132+
Upon failure, this method returns ``-1.0`` with an exception set, so one
125133
should call :c:func:`PyErr_Occurred` to check for errors.
126134
127135
.. versionchanged:: 3.13
@@ -135,8 +143,10 @@ Complex Numbers as Python Objects
135143
:meth:`~object.__complex__` method, this method will first be called to
136144
convert *op* to a Python complex number object. If :meth:`!__complex__` is
137145
not defined then it falls back to call :c:func:`PyFloat_AsDouble` and
138-
returns ``0.0`` on success. Upon failure, this method returns ``-1.0``, so
139-
one should call :c:func:`PyErr_Occurred` to check for errors.
146+
returns ``0.0`` on success.
147+
148+
Upon failure, this method returns ``-1.0`` with an exception set, so one
149+
should call :c:func:`PyErr_Occurred` to check for errors.
140150
141151
.. versionchanged:: 3.13
142152
Use :meth:`~object.__complex__` if available.
@@ -149,8 +159,11 @@ Complex Numbers as Python Objects
149159
method, this method will first be called to convert *op* to a Python complex
150160
number object. If :meth:`!__complex__` is not defined then it falls back to
151161
:meth:`~object.__float__`. If :meth:`!__float__` is not defined then it falls back
152-
to :meth:`~object.__index__`. Upon failure, this method returns ``-1.0`` as a real
153-
value.
162+
to :meth:`~object.__index__`.
163+
164+
Upon failure, this method returns :c:type:`Py_complex`
165+
with :c:member:`~Py_complex.real` set to ``-1.0`` and with an exception set, so one
166+
should call :c:func:`PyErr_Occurred` to check for errors.
154167
155168
.. versionchanged:: 3.8
156169
Use :meth:`~object.__index__` if available.

0 commit comments

Comments
 (0)