diff options
author | Brett Cannon <brett@python.org> | 2012-11-15 16:13:00 -0500 |
---|---|---|
committer | Brett Cannon <brett@python.org> | 2012-11-15 16:13:00 -0500 |
commit | 0676caf66082af23806f2316e4debf2c70bf9cf5 (patch) | |
tree | 658f8dd40f1a40694fa27e6b456c644ce4009f43 /Lib/fractions.py | |
parent | 27b6793c72b8e74808997c3fc3e2ff7e912b0887 (diff) | |
parent | 73726aac0fada5a94587fde7ba48aa0699e59bc9 (diff) | |
download | cpython-git-0676caf66082af23806f2316e4debf2c70bf9cf5.tar.gz |
merge
Diffstat (limited to 'Lib/fractions.py')
-rw-r--r-- | Lib/fractions.py | 14 |
1 files changed, 9 insertions, 5 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py index 8be52d2db8..79e83ff2c0 100644 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -182,8 +182,10 @@ class Fraction(numbers.Rational): elif not isinstance(f, float): raise TypeError("%s.from_float() only takes floats, not %r (%s)" % (cls.__name__, f, type(f).__name__)) - if math.isnan(f) or math.isinf(f): - raise TypeError("Cannot convert %r to %s." % (f, cls.__name__)) + if math.isnan(f): + raise ValueError("Cannot convert %r to %s." % (f, cls.__name__)) + if math.isinf(f): + raise OverflowError("Cannot convert %r to %s." % (f, cls.__name__)) return cls(*f.as_integer_ratio()) @classmethod @@ -196,9 +198,11 @@ class Fraction(numbers.Rational): raise TypeError( "%s.from_decimal() only takes Decimals, not %r (%s)" % (cls.__name__, dec, type(dec).__name__)) - if not dec.is_finite(): - # Catches infinities and nans. - raise TypeError("Cannot convert %s to %s." % (dec, cls.__name__)) + if dec.is_infinite(): + raise OverflowError( + "Cannot convert %s to %s." % (dec, cls.__name__)) + if dec.is_nan(): + raise ValueError("Cannot convert %s to %s." % (dec, cls.__name__)) sign, digits, exp = dec.as_tuple() digits = int(''.join(map(str, digits))) if sign: |