Index: decimal.py =================================================================== RCS file: /cvsroot/python/python/dist/src/Lib/decimal.py,v retrieving revision 1.35 diff -u -r1.35 decimal.py --- decimal.py 15 Mar 2005 04:59:16 -0000 1.35 +++ decimal.py 19 Mar 2005 18:56:14 -0000 @@ -645,6 +645,8 @@ def __cmp__(self, other, context=None): other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if self._is_special or other._is_special: ans = self._check_nans(other, context) @@ -714,6 +716,8 @@ Like __cmp__, but returns Decimal instances. """ other = _convert_other(other) + if other == NotImplemented: + return NotImplemented #compare(NaN, NaN) = NaN if (self._is_special or other and other._is_special): @@ -919,6 +923,8 @@ -INF + INF (or the reverse) cause InvalidOperation errors. """ other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if context is None: context = getcontext() @@ -1006,6 +1012,8 @@ def __sub__(self, other, context=None): """Return self + (-other)""" other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if self._is_special or other._is_special: ans = self._check_nans(other, context=context) @@ -1023,6 +1031,8 @@ def __rsub__(self, other, context=None): """Return other + (-self)""" other = _convert_other(other) + if other == NotImplemented: + return NotImplemented tmp = Decimal(self) tmp._sign = 1 - tmp._sign @@ -1068,6 +1078,8 @@ (+-) INF * 0 (or its reverse) raise InvalidOperation. """ other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if context is None: context = getcontext() @@ -1140,6 +1152,8 @@ computing the other value are not raised. """ other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if context is None: context = getcontext() @@ -1292,6 +1306,8 @@ def __rdiv__(self, other, context=None): """Swaps self/other and returns __div__.""" other = _convert_other(other) + if other == NotImplemented: + return NotImplemented return other.__div__(self, context=context) __rtruediv__ = __rdiv__ @@ -1304,6 +1320,8 @@ def __rdivmod__(self, other, context=None): """Swaps self/other and returns __divmod__.""" other = _convert_other(other) + if other == NotImplemented: + return NotImplemented return other.__divmod__(self, context=context) def __mod__(self, other, context=None): @@ -1311,6 +1329,8 @@ self % other """ other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if self._is_special or other._is_special: ans = self._check_nans(other, context) @@ -1325,6 +1345,8 @@ def __rmod__(self, other, context=None): """Swaps self/other and returns __mod__.""" other = _convert_other(other) + if other == NotImplemented: + return NotImplemented return other.__mod__(self, context=context) def remainder_near(self, other, context=None): @@ -1332,6 +1354,8 @@ Remainder nearest to 0- abs(remainder-near) <= other/2 """ other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if self._is_special or other._is_special: ans = self._check_nans(other, context) @@ -1411,6 +1435,8 @@ def __rfloordiv__(self, other, context=None): """Swaps self/other and returns __floordiv__.""" other = _convert_other(other) + if other == NotImplemented: + return NotImplemented return other.__floordiv__(self, context=context) def __float__(self): @@ -1661,6 +1687,8 @@ If modulo is None (default), don't take it mod modulo. """ n = _convert_other(n) + if n == NotImplemented: + return NotImplemented if context is None: context = getcontext() @@ -1747,6 +1775,8 @@ def __rpow__(self, other, context=None): """Swaps self/other and returns __pow__.""" other = _convert_other(other) + if other == NotImplemented: + return NotImplemented return other.__pow__(self, context=context) def normalize(self, context=None): @@ -2001,6 +2031,8 @@ NaN (and signals if one is sNaN). Also rounds. """ other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if self._is_special or other._is_special: # if one operand is a quiet NaN and the other is number, then the @@ -2048,6 +2080,8 @@ NaN (and signals if one is sNaN). Also rounds. """ other = _convert_other(other) + if other == NotImplemented: + return NotImplemented if self._is_special or other._is_special: # if one operand is a quiet NaN and the other is number, then the @@ -2875,7 +2909,7 @@ if isinstance(other, (int, long)): return Decimal(other) - raise TypeError, "You can interact Decimal only with int, long or Decimal data types." + return NotImplemented _infinity_map = { 'inf' : 1,