On Wed, Oct 7, 2020 at 12:41 AM Serhiy Storchaka <storch...@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) *Pronouns: he/him **(why is my pronoun here?)* <http://feministing.com/2015/02/03/how-using-they-as-a-singular-pronoun-can-change-the-world/>
_______________________________________________ Python-ideas mailing list -- python-ideas@python.org To unsubscribe send an email to python-ideas-le...@python.org https://mail.python.org/mailman3/lists/python-ideas.python.org/ Message archived at https://mail.python.org/archives/list/python-ideas@python.org/message/KT4JNNL6NL4L77AAQBK67GQH7U5NJ5BP/ Code of Conduct: http://python.org/psf/codeofconduct/