diff options
author | Sergey B Kirpichev <skirpichev@gmail.com> | 2024-01-15 15:04:17 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2024-01-15 15:04:17 (GMT) |
commit | 0f2fa6150baf111a6c69d5d491c95c3c2ee60eaf (patch) | |
tree | e60136c4ac8da4e44cd3bdf4a702372be34a96d1 /Misc | |
parent | ac10947ba79a15bfdaa3ca92c6864214648ab364 (diff) | |
download | cpython-0f2fa6150baf111a6c69d5d491c95c3c2ee60eaf.zip cpython-0f2fa6150baf111a6c69d5d491c95c3c2ee60eaf.tar.gz cpython-0f2fa6150baf111a6c69d5d491c95c3c2ee60eaf.tar.bz2 |
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.
Diffstat (limited to 'Misc')
-rw-r--r-- | Misc/NEWS.d/next/Core and Builtins/2023-09-21-11-54-28.gh-issue-109598.CRidSy.rst | 3 |
1 files changed, 3 insertions, 0 deletions
diff --git a/Misc/NEWS.d/next/Core and Builtins/2023-09-21-11-54-28.gh-issue-109598.CRidSy.rst b/Misc/NEWS.d/next/Core and Builtins/2023-09-21-11-54-28.gh-issue-109598.CRidSy.rst new file mode 100644 index 0000000..3eedc45 --- /dev/null +++ b/Misc/NEWS.d/next/Core and Builtins/2023-09-21-11-54-28.gh-issue-109598.CRidSy.rst @@ -0,0 +1,3 @@ +:c:func:`PyComplex_RealAsDouble`/:c:func:`PyComplex_ImagAsDouble` now tries to +convert an object to a :class:`complex` instance using its ``__complex__()`` method +before falling back to the ``__float__()`` method. Patch by Sergey B Kirpichev. |