07.10.20 18:43, Guido van Rossum пише:
> 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.)

It is easy to fix. The trend is that functions which accept several
different types of arguments should mention them all in a type error
message instead of just the last one (e.g. "must be string, got
'complex'" while real numbers are accepted too).

See https://bugs.python.org/issue41974.

> 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.

What are problems with Decimal?
_______________________________________________
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/YABHVAPVBWDFHXBNKTBUQGXCJBHWHWKX/
Code of Conduct: http://python.org/psf/codeofconduct/

Reply via email to