]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-109598: make PyComplex_RealAsDouble/ImagAsDouble use __complex__ (GH-109647)
authorSergey B Kirpichev <skirpichev@gmail.com>
Mon, 15 Jan 2024 15:04:17 +0000 (18:04 +0300)
committerGitHub <noreply@github.com>
Mon, 15 Jan 2024 15:04:17 +0000 (16:04 +0100)
commit0f2fa6150baf111a6c69d5d491c95c3c2ee60eaf
treee60136c4ac8da4e44cd3bdf4a702372be34a96d1
parentac10947ba79a15bfdaa3ca92c6864214648ab364
gh-109598: make PyComplex_RealAsDouble/ImagAsDouble use __complex__ (GH-109647)

`PyComplex_RealAsDouble()`/`PyComplex_ImagAsDouble` now try to convert
an object to a `complex` instance using its `__complex__()` method
before falling back to the ``__float__()`` method.

PyComplex_ImagAsDouble() also will not silently return 0.0 for
non-complex types anymore.  Instead we try to call PyFloat_AsDouble()
and return 0.0 only if this call is successful.
Doc/c-api/complex.rst
Lib/test/test_capi/test_complex.py
Misc/NEWS.d/next/Core and Builtins/2023-09-21-11-54-28.gh-issue-109598.CRidSy.rst [new file with mode: 0644]
Objects/complexobject.c