From: Mark Dickinson Date: Sun, 25 Jan 2009 10:39:15 +0000 (+0000) Subject: Remove uses of cmp from the decimal module. X-Git-Tag: v2.7a1~2209 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=e52c31450dfbe649b559b3fa96630d348b838c19;p=python Remove uses of cmp from the decimal module. --- diff --git a/Lib/decimal.py b/Lib/decimal.py index 4140bea2f2..87bd142048 100644 --- a/Lib/decimal.py +++ b/Lib/decimal.py @@ -801,9 +801,16 @@ class Decimal(object): if self > other. This routine is for internal use only.""" if self._is_special or other._is_special: - return cmp(self._isinfinity(), other._isinfinity()) + self_inf = self._isinfinity() + other_inf = other._isinfinity() + if self_inf == other_inf: + return 0 + elif self_inf < other_inf: + return -1 + else: + return 1 - # check for zeros; note that cmp(0, -0) should return 0 + # check for zeros; Decimal('0') == Decimal('-0') if not self: if not other: return 0 @@ -823,7 +830,12 @@ class Decimal(object): if self_adjusted == other_adjusted: self_padded = self._int + '0'*(self._exp - other._exp) other_padded = other._int + '0'*(other._exp - self._exp) - return cmp(self_padded, other_padded) * (-1)**self._sign + if self_padded == other_padded: + return 0 + elif self_padded < other_padded: + return -(-1)**self._sign + else: + return (-1)**self._sign elif self_adjusted > other_adjusted: return (-1)**self._sign else: # self_adjusted < other_adjusted