This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author mark.dickinson
Recipients corona10, ethan smith, gvanrossum, gyu-don, mark.dickinson, serhiy.storchaka, terry.reedy
Date 2021-08-22.11:16:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1629630994.62.0.645316546429.issue24234@roundup.psfhosted.org>
In-reply-to
Content
> [...] we'll need `int.__complex__` and `float.__complex__` implementations as well as `complex.__complex__`.

The real problem here is that the "typing.SupportsComplex" protocol isn't a good match for code that needs to know that a given value `x` can be treated as though it were a complex number.

The test that best matches "usable as a complex number" seems to be that type(x) implements at least one of `__index__`, `__float__` or `__complex__`, or that `x` is a subclass of complex.

It looks to me as though the right thing to do here is to just implement complex.__complex__, but not int.__complex__ or float.__complex__.  Then at least we can remove the subclass test from the above and express the test purely in terms of special methods: __index__, __float__ and __complex__. And then perhaps it's for the typing module to find a more convenient way to express the union of typing.SupportsIndex, typing.SupportsFloat and typing.SupportsComplex.
History
Date User Action Args
2021-08-22 11:16:34mark.dickinsonsetrecipients: + mark.dickinson, gvanrossum, terry.reedy, serhiy.storchaka, ethan smith, corona10, gyu-don
2021-08-22 11:16:34mark.dickinsonsetmessageid: <1629630994.62.0.645316546429.issue24234@roundup.psfhosted.org>
2021-08-22 11:16:34mark.dickinsonlinkissue24234 messages
2021-08-22 11:16:34mark.dickinsoncreate