Invalid "equivalents" of the complex type constructor in docs · Issue #109218 · python/cpython (original) (raw)

The sphinx docs says:

class complex(real=0, imag=0)
[...]
Return a complex number with the value real + imag*1j or convert a string or number to a complex number.
[...]

The docstring (btw it doesn't mention a string as an argument):

>>> print(complex.__doc__)
Create a complex number from a real part and an optional imaginary part.

This is equivalent to (real + imag*1j) where imag defaults to 0.

That wrong, e.g.:

complex(0.0, -0.0) -0j 0.0 + (-0.0)*1j 0j complex(-0.0, -0.0) (-0-0j) -0.0 + (-0.0)1j (-0+0j) complex(-0.0, 0.0) (-0+0j) -0.0 + 0.01j 0j

Here is an attempt (patch) to solve, let me know if this is worth a PR:

diff --git a/Doc/library/functions.rst b/Doc/library/functions.rst index d9974c6350..78b85658ef 100644 --- a/Doc/library/functions.rst +++ b/Doc/library/functions.rst @@ -373,8 +373,8 @@ are always available. They are listed here in alphabetical order. .. class:: complex(real=0, imag=0) complex(string)

-Create a complex number from a real part and an optional imaginary part.

-This is equivalent to (real + imag1j) where imag defaults to 0. +Create a complex number from a real part and an optional imaginary part +or convert a string to a complex number. [clinic start generated code]/

static PyObject *

Edit:
Another instance of this issue is in the cmath docs:

A Python complex number z is stored internally using rectangular or Cartesian coordinates. It is completely determined by its real part z.real and its imaginary part z.imag. In other words::

z == z.real + z.imag*1j

E.g.:

from cmath import inf complex(0.0, inf) infj 0.0 + inf*1j (nan+infj)

Linked PRs