Message400068
> [...] 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. |
|
Date |
User |
Action |
Args |
2021-08-22 11:16:34 | mark.dickinson | set | recipients:
+ mark.dickinson, gvanrossum, terry.reedy, serhiy.storchaka, ethan smith, corona10, gyu-don |
2021-08-22 11:16:34 | mark.dickinson | set | messageid: <1629630994.62.0.645316546429.issue24234@roundup.psfhosted.org> |
2021-08-22 11:16:34 | mark.dickinson | link | issue24234 messages |
2021-08-22 11:16:34 | mark.dickinson | create | |
|