On Wed, Oct 7, 2020 at 12:41 AM Serhiy Storchaka <storchaka@gmail.com> wrote:
07.10.20 06:04, Guido van Rossum пише:
> Ironically, complex numbers have a `__float__`
> method that always fails, and floats don't have a `__complex__` method
> but complex(x) succeeds if x is a float...

I wonder why not remove complex.__float__ (and complex.__int__,
complex.__floordiv__, etc)?

Usability in a different context.
```
>>> z = 1j
>>> float(z)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: can't convert complex to float
>>> float(object())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: float() argument must be a string or a number, not 'object'
>>>
```
If float(z) gave the second error message it would be rather confusing, since z is a number. I guess the alternative would be to explicitly check for complex in float() when producing the error message. (Or phrase it as "real number", which actually might work.)

I think you have pointed into a reasonable way forward -- make the types match the intention of the protocols better.

I'm not sure what to do about Decimal though. I suspect we will end up making changes to both the numbers and decimal modules.
 
--
--Guido van Rossum (python.org/~guido)