homepage

This issue tracker has been migrated to GitHub , and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author terry.reedy
Recipients ezio.melotti, mark.dickinson, terry.reedy
Date 2012年08月29日.19:24:40
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1346268284.86.0.294059613354.issue15815@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2012年08月29日 19:24:45terry.reedysetrecipients: + terry.reedy, mark.dickinson, ezio.melotti
2012年08月29日 19:24:44terry.reedysetmessageid: <1346268284.86.0.294059613354.issue15815@psf.upfronthosting.co.za>
2012年08月29日 19:24:43terry.reedylinkissue15815 messages
2012年08月29日 19:24:40terry.reedycreate

AltStyle によって変換されたページ (->オリジナル) /