33from sympy .core .cache import cacheit
44from sympy .core .core import BasicType , C
55from sympy .core .sympify import _sympify , sympify , SympifyError
6- from sympy .core .compatibility import (reduce , cmp , iterable ,
7- Iterator , ordered , string_types , with_metaclass )
6+ from sympy .core .compatibility import (reduce , iterable , Iterator , ordered ,
7+ string_types , with_metaclass )
88from sympy .core .decorators import deprecated
99from sympy .core .singleton import S
1010
@@ -172,16 +172,18 @@ def compare(self, other):
172172
173173 """
174174 # all redefinitions of __cmp__ method should start with the
175- # following three lines:
175+ # following lines:
176176 if self is other :
177177 return 0
178- c = cmp (self .__class__ , other .__class__ )
178+ n1 = self .__class__
179+ n2 = other .__class__
180+ c = (n1 > n2 ) - (n1 < n2 )
179181 if c :
180182 return c
181183 #
182184 st = self ._hashable_content ()
183185 ot = other ._hashable_content ()
184- c = cmp (len (st ), len (ot ))
186+ c = (len (st ) > len ( ot )) - ( len ( st ) < len (ot ))
185187 if c :
186188 return c
187189 for l , r in zip (st , ot ):
@@ -190,7 +192,7 @@ def compare(self, other):
190192 elif isinstance (l , frozenset ):
191193 c = 0
192194 else :
193- c = cmp ( l , r )
195+ c = ( l > r ) - ( l < r )
194196 if c :
195197 return c
196198 return 0
@@ -204,7 +206,9 @@ def _compare_pretty(a, b):
204206 return - 1
205207
206208 if a .is_Rational and b .is_Rational :
207- return cmp (a .p * b .q , b .p * a .q )
209+ l = a .p * b .q
210+ r = b .p * a .q
211+ return (l > r ) - (l < r )
208212 else :
209213 from sympy .core .symbol import Wild
210214 p1 , p2 , p3 = Wild ("p1" ), Wild ("p2" ), Wild ("p3" )
@@ -269,18 +273,13 @@ def compare_pretty(a, b):
269273 except SympifyError :
270274 pass
271275
272- # both objects are non-SymPy
273- if (not isinstance (a , Basic )) and (not isinstance (b , Basic )):
274- return cmp (a , b )
275-
276- if not isinstance (a , Basic ):
277- return - 1 # other < sympy
278-
279276 if not isinstance (b , Basic ):
280277 return + 1 # sympy > other
281278
282279 # now both objects are from SymPy, so we can proceed to usual comparison
283- return cmp (a .sort_key (), b .sort_key ())
280+ a = a .sort_key ()
281+ b = b .sort_key ()
282+ return (a > b ) - (a < b )
284283
285284 @classmethod
286285 def fromiter (cls , args , ** assumptions ):
0 commit comments