On Wed, Oct 7, 2020, 3:43 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)?
>

I wonder the same thing myself and I bet it gets complicated fast.

I was trying to use the numbers module to type hint any number including
both floats and decimal.Decimal the other evening. It doesn't work... type
checkers don't know Decimal is a Number. Finally I discovered the correct
current solution is just Union[Decimal, float] or Union[Decimal, float,
Real] if you want to include other real numbers like fractions.Fraction.

St first I was really annoyed but from what I was able to gather after some
reading Monday evening, this is a known problem that is getting worked on
and is because the abcs in the current numbers module are somewhat unusable
for type hinting and need to be replaced/updated to make Number and friends
into protocols. And I came away grateful there are smart people people
working on this to make things better, rather than annoyed. I'll be
interested to see what is come up with as a solution in 3.10.
_______________________________________________
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/QUFFYVQSEFTUSDSQ2XAGJFLSHOB4C4AG/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to