diff --git a/sympy/core/numbers.py b/sympy/core/numbers.py index a21bfec58bda..78ef86a56a06 100644 --- a/sympy/core/numbers.py +++ b/sympy/core/numbers.py @@ -56,10 +56,16 @@ def seterr(divide=False): def _decimal_to_Rational_prec(dec): """Convert an ordinary decimal instance to a Rational.""" - assert not dec._is_special + # _is_special is needed for Python 2.5 support; is_finite for Python 3.3 + # support + nonfinite = getattr(dec, '_is_special', None) + if nonfinite is None: + nonfinite = not dec.is_finite() + if nonfinite: + raise TypeError("dec must be finite, got %s." % dec) s, d, e = dec.as_tuple() prec = len(d) - if dec._isinteger(): + if int(dec) == dec: rv = Rational(int(dec)) else: s = (-1)**s