Skip to content

Commit d6e34fd

Browse files
Merge pull request #28484 from merintheres/remove-cmp
Remove leftover Python 2 __cmp__ references
2 parents 1eb7b6a + e861b1c commit d6e34fd

File tree

8 files changed

+5
-68
lines changed

8 files changed

+5
-68
lines changed

sympy/core/basic.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ def compare(self, other):
389389
1
390390
391391
"""
392-
# all redefinitions of __cmp__ method should start with the
392+
# all redefinitions of compare method should start with the
393393
# following lines:
394394
if self is other:
395395
return 0

sympy/core/logic.py

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -246,20 +246,6 @@ def __ne__(a, b):
246246
else:
247247
return a.args != b.args
248248

249-
def __lt__(self, other):
250-
if self.__cmp__(other) == -1:
251-
return True
252-
return False
253-
254-
def __cmp__(self, other):
255-
if type(self) is not type(other):
256-
a = str(type(self))
257-
b = str(type(other))
258-
else:
259-
a = self.args
260-
b = other.args
261-
return (a > b) - (a < b)
262-
263249
def __str__(self):
264250
return '%s(%s)' % (self.__class__.__name__,
265251
', '.join(str(a) for a in self.args))

sympy/core/tests/test_logic.py

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -63,23 +63,6 @@ def test_fuzzy_or():
6363
raises(TypeError, lambda: fuzzy_or())
6464

6565

66-
def test_logic_cmp():
67-
l1 = And('a', Not('b'))
68-
l2 = And('a', Not('b'))
69-
70-
assert hash(l1) == hash(l2)
71-
assert (l1 == l2) == T
72-
assert (l1 != l2) == F
73-
74-
assert And('a', 'b', 'c') == And('b', 'a', 'c')
75-
assert And('a', 'b', 'c') == And('c', 'b', 'a')
76-
assert And('a', 'b', 'c') == And('c', 'a', 'b')
77-
78-
assert Not('a') < Not('b')
79-
assert (Not('b') < Not('a')) is False
80-
assert (Not('a') < 2) is False
81-
82-
8366
def test_logic_onearg():
8467
assert And() is True
8568
assert Or() is False

sympy/geometry/entity.py

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@
3939
from sympy.utilities.iterables import is_sequence
4040

4141

42-
# How entities are ordered; used by __cmp__ in GeometryEntity
42+
# How entities are ordered; used for comparison in GeometryEntity
4343
ordering_of_classes = [
4444
"Point2D",
4545
"Point3D",
@@ -78,36 +78,6 @@ class GeometryEntity(Basic, EvalfMixin):
7878

7979
__slots__: tuple[str, ...] = ()
8080

81-
def __cmp__(self, other):
82-
"""Comparison of two GeometryEntities."""
83-
n1 = self.__class__.__name__
84-
n2 = other.__class__.__name__
85-
c = (n1 > n2) - (n1 < n2)
86-
if not c:
87-
return 0
88-
89-
i1 = -1
90-
for cls in self.__class__.__mro__:
91-
try:
92-
i1 = ordering_of_classes.index(cls.__name__)
93-
break
94-
except ValueError:
95-
i1 = -1
96-
if i1 == -1:
97-
return c
98-
99-
i2 = -1
100-
for cls in other.__class__.__mro__:
101-
try:
102-
i2 = ordering_of_classes.index(cls.__name__)
103-
break
104-
except ValueError:
105-
i2 = -1
106-
if i2 == -1:
107-
return c
108-
109-
return (i1 > i2) - (i1 < i2)
110-
11181
def __contains__(self, other):
11282
"""Subclasses should implement this method for anything more complex than equality."""
11383
if type(self) is type(other):

sympy/geometry/tests/test_ellipse.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,6 @@ def test_ellipse_geom():
116116
assert hash(c1) == hash(Circle(Point(1, 0), Point(0, 1), Point(0, -1)))
117117
assert c1 in e1
118118
assert (Line(p1, p2) in e1) is False
119-
assert e1.__cmp__(e1) == 0
120-
assert e1.__cmp__(Point(0, 0)) > 0
121119

122120
# Encloses
123121
assert e1.encloses(Segment(Point(-0.5, -0.5), Point(0.5, 0.5))) is True

sympy/physics/quantum/anticommutator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class AntiCommutator(Expr):
3131
3232
Canonical ordering of an anticommutator is ``{A, B}`` for ``A < B``. The
3333
arguments of the anticommutator are put into canonical order using
34-
``__cmp__``. If ``B < A``, then ``{A, B}`` is returned as ``{B, A}``.
34+
comparison operators. If ``B < A``, then ``{A, B}`` is returned as ``{B, A}``.
3535
3636
Parameters
3737
==========

sympy/physics/quantum/commutator.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ class returns the commutator in an unevaluated form. To evaluate the
3232
commutator, use the ``.doit()`` method.
3333
3434
Canonical ordering of a commutator is ``[A, B]`` for ``A < B``. The
35-
arguments of the commutator are put into canonical order using ``__cmp__``.
35+
arguments of the commutator are put into canonical order using comparison operators.
3636
If ``B < A``, then ``[B, A]`` is returned as ``-[A, B]``.
3737
3838
Parameters

sympy/physics/secondquant.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1655,7 +1655,7 @@ class Commutator(Function):
16551655
"""
16561656
The Commutator: [A, B] = A*B - B*A
16571657
1658-
The arguments are ordered according to .__cmp__()
1658+
The arguments are ordered according to comparison operators
16591659
16601660
Examples
16611661
========

0 commit comments

Comments
 (0)