Skip to content

Commit 03f6803

Browse files
committed
pythongh-121834: Improve complex C-API docs
1 parent 7e91e0d commit 03f6803

1 file changed

Lines changed: 14 additions & 5 deletions

File tree

‎Doc/c-api/complex.rst‎

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,11 +106,13 @@ Complex Numbers as Python Objects
106106
.. c:function:: PyObject* PyComplex_FromCComplex(Py_complex v)
107107
108108
Create a new Python complex number object from a C :c:type:`Py_complex` value.
109+
Return ``NULL`` with an exception set on error.
109110
110111
111112
.. c:function:: PyObject* PyComplex_FromDoubles(double real, double imag)
112113
113114
Return a new :c:type:`PyComplexObject` object from *real* and *imag*.
115+
Return ``NULL`` with an exception set on error.
114116
115117
116118
.. c:function:: double PyComplex_RealAsDouble(PyObject *op)
@@ -121,7 +123,9 @@ Complex Numbers as Python Objects
121123
:meth:`~object.__complex__` method, this method will first be called to
122124
convert *op* to a Python complex number object. If :meth:`!__complex__` is
123125
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
126+
returns its result.
127+
128+
Upon failure, this method returns ``-1.0`` with an exception set, so one
125129
should call :c:func:`PyErr_Occurred` to check for errors.
126130
127131
.. versionchanged:: 3.13
@@ -135,8 +139,10 @@ Complex Numbers as Python Objects
135139
:meth:`~object.__complex__` method, this method will first be called to
136140
convert *op* to a Python complex number object. If :meth:`!__complex__` is
137141
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.
142+
returns ``0.0`` on success.
143+
144+
Upon failure, this method returns ``-1.0`` with an exception set, so one
145+
should call :c:func:`PyErr_Occurred` to check for errors.
140146
141147
.. versionchanged:: 3.13
142148
Use :meth:`~object.__complex__` if available.
@@ -149,8 +155,11 @@ Complex Numbers as Python Objects
149155
method, this method will first be called to convert *op* to a Python complex
150156
number object. If :meth:`!__complex__` is not defined then it falls back to
151157
: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.
158+
to :meth:`~object.__index__`.
159+
160+
Upon failure, this method returns :c:type:`Py_complex`
161+
with ``.real`` set to ``-1.0`` and with an exception set, so one
162+
should call :c:func:`PyErr_Occurred` to check for errors.
154163
155164
.. versionchanged:: 3.8
156165
Use :meth:`~object.__index__` if available.

0 commit comments

Comments
 (0)