Skip to content

gh-109598: make PyComplex_RealAsDouble/ImagAsDouble use __complex__#109647

Merged
encukou merged 8 commits into
python:mainfrom
skirpichev:complex-realimag-asdouble
Jan 15, 2024
Merged

gh-109598: make PyComplex_RealAsDouble/ImagAsDouble use __complex__#109647
encukou merged 8 commits into
python:mainfrom
skirpichev:complex-realimag-asdouble

Conversation

@skirpichev

@skirpichev skirpichev commented Sep 21, 2023

Copy link
Copy Markdown
Member

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.


📚 Documentation preview 📚: https://cpython-previews--109647.org.readthedocs.build/

…ex__

* 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.
* Full test coverage for changed functions.
@skirpichev skirpichev force-pushed the complex-realimag-asdouble branch from 8a9d9dd to 0e07b65 Compare September 21, 2023 12:39
Comment thread Objects/complexobject.c
@skirpichev skirpichev requested a review from Ogb-Bassey October 6, 2023 02:10
@skirpichev

Copy link
Copy Markdown
Member Author

CC @mdickinson as suggested by https://devguide.python.org/experts/

@skirpichev

This comment was marked as resolved.

@skirpichev skirpichev marked this pull request as draft November 2, 2023 03:17
@skirpichev skirpichev marked this pull request as ready for review November 5, 2023 11:14
@skirpichev

This comment was marked as resolved.

@skirpichev

Copy link
Copy Markdown
Member Author

@gvanrossum gvanrossum left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM. Very thorough.

@encukou encukou merged commit 0f2fa61 into python:main Jan 15, 2024
@skirpichev skirpichev deleted the complex-realimag-asdouble branch January 15, 2024 23:42
kulikjak pushed a commit to kulikjak/cpython that referenced this pull request Jan 22, 2024
…ex__ (pythonGH-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.
aisk pushed a commit to aisk/cpython that referenced this pull request Feb 11, 2024
…ex__ (pythonGH-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.
Glyphack pushed a commit to Glyphack/cpython that referenced this pull request Sep 2, 2024
…ex__ (pythonGH-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.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants