I propose that we add 'of ####' to all ZeroDivisionError messagesso it is less necessary to use a debugger to add print statements to recover the information currently tossed away. (I also propose to change denominator from 'zero' to '0', '0.0', '0+0j', as appropriate.)
>>> 3//0
...
ZeroDivisionError: integer division or modulo by zero
# augment to
ZeroDivisionError: integer division or modulo of 3 by 0
Similarly for
>>> 3 / 0
ZeroDivisionError: division by zero
# perhaps this should be 'true division of 3 by 0'
>>> 3.0 / 0.0
ZeroDivisionError: float division by zero
>>> (3+3j) / (0+0j)
ZeroDivisionError: complex division by zero
In #7482 it was proposed to make float and complex messages same as int message by adding 'or modulo'. I an not sure why not to do that, or if it was just deferred.
Fractions currently print the numerator as part of an invalid numerator / 0 result from *either* construction or division.
>>> from fractions import Fraction as F
>>> F(3, 0)
Traceback (most recent call last):
File "<pyshell#20>", line 1, in <module>
F(3, 0)
File "C:\Programs\Python33\lib\fractions.py", line 167, in __new__
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
ZeroDivisionError: Fraction(3, 0)
# Here, 'Fraction(3, 0)' is invalid input.
>>> F(3, 1) / F(0, 1)
Traceback (most recent call last):
File "<pyshell#19>", line 1, in <module>
F(3, 1) / F(0, 1)
File "C:\Programs\Python33\lib\fractions.py", line 367, in forward
return monomorphic_operator(a, b)
File "C:\Programs\Python33\lib\fractions.py", line 417, in _div
a.denominator * b.numerator)
File "C:\Programs\Python33\lib\fractions.py", line 167, in __new__
raise ZeroDivisionError('Fraction(%s, 0)' % numerator)
ZeroDivisionError: Fraction(3, 0)
# Here, 'Fraction(3, 0)' is invalid output.
I found this confusing until I worked out the dual meaning. I think
ZeroDevisionError: invalid Fraction(3, 0) from construction or division
might be a bit clearer.
I have not looked at decimals. |