
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?