Author casevh
Recipients casevh
Date 2012-11-14.06:30:19
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1352874620.08.0.771603502235.issue16469@psf.upfronthosting.co.za>
In-reply-to
Content
When attempting to convert a float("nan"), float("inf"), or float("-inf"), fractions.Fraction() raises different exceptions than int()

>>> int(float("nan"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ValueError: cannot convert float NaN to integer
>>> fractions.Fraction(float("nan"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/lib/python3.2/fractions.py", line 114, in __new__
    value = Fraction.from_float(numerator)
  File "/opt/local/lib/python3.2/fractions.py", line 186, in from_float
    raise TypeError("Cannot convert %r to %s." % (f, cls.__name__))
TypeError: Cannot convert nan to Fraction.
>>> int(float("inf"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: cannot convert float infinity to integer
>>> fractions.Fraction(float("inf"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/lib/python3.2/fractions.py", line 114, in __new__
    value = Fraction.from_float(numerator)
  File "/opt/local/lib/python3.2/fractions.py", line 186, in from_float
    raise TypeError("Cannot convert %r to %s." % (f, cls.__name__))
TypeError: Cannot convert inf to Fraction.
>>> int(float("-inf"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
OverflowError: cannot convert float infinity to integer
>>> fractions.Fraction(float("-inf"))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/opt/local/lib/python3.2/fractions.py", line 114, in __new__
    value = Fraction.from_float(numerator)
  File "/opt/local/lib/python3.2/fractions.py", line 186, in from_float
    raise TypeError("Cannot convert %r to %s." % (f, cls.__name__))
TypeError: Cannot convert -inf to Fraction.

Should the exceptions be changed to ValueError and OverflowError?
History
Date User Action Args
2012-11-14 06:30:20casevhsetrecipients: + casevh
2012-11-14 06:30:20casevhsetmessageid: <1352874620.08.0.771603502235.issue16469@psf.upfronthosting.co.za>
2012-11-14 06:30:20casevhlinkissue16469 messages
2012-11-14 06:30:19casevhcreate