diff options
Diffstat (limited to 'Lib/fractions.py')
-rwxr-xr-x | Lib/fractions.py | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/Lib/fractions.py b/Lib/fractions.py index 3df628adc0b..bc065243d41 100755 --- a/Lib/fractions.py +++ b/Lib/fractions.py @@ -108,7 +108,9 @@ class Fraction(numbers.Rational): Beware that Fraction.from_float(0.3) != Fraction(3, 10). """ - if not isinstance(f, float): + if isinstance(f, numbers.Integral): + f = float(f) + 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): @@ -119,7 +121,9 @@ class Fraction(numbers.Rational): def from_decimal(cls, dec): """Converts a finite Decimal instance to a rational number, exactly.""" from decimal import Decimal - if not isinstance(dec, Decimal): + if isinstance(dec, numbers.Integral): + dec = Decimal(int(dec)) + elif not isinstance(dec, Decimal): raise TypeError( "%s.from_decimal() only takes Decimals, not %r (%s)" % (cls.__name__, dec, type(dec).__name__)) |