Commits

Antonio Cuni committed 7195432

in cpython array.array define tp_richcompare, not tp_compare; do the equivalent for pypy

  • Participants
  • Parent commits d0b0ec9

Comments (0)

Files changed (2)

File pypy/module/array/interp_array.py

             raise OperationError(space.w_ValueError, space.wrap(msg))
 
     # Compare methods
-    def cmp__Array_ANY(space, self, other):
+    def _cmp_impl(space, self, other, space_fn):
         if isinstance(other, W_ArrayBase):
             w_lst1 = array_tolist__Array(space, self)
             w_lst2 = space.call_method(other, 'tolist')
-            return space.cmp(w_lst1, w_lst2)
+            return space_fn(w_lst1, w_lst2)
         else:
             return space.w_NotImplemented
 
+    def eq__Array_ANY(space, self, other):
+        return _cmp_impl(space, self, other, space.eq)
+
+    def ne__Array_ANY(space, self, other):
+        return _cmp_impl(space, self, other, space.ne)
+
+    def lt__Array_ANY(space, self, other):
+        return _cmp_impl(space, self, other, space.lt)
+
+    def le__Array_ANY(space, self, other):
+        return _cmp_impl(space, self, other, space.le)
+
+    def gt__Array_ANY(space, self, other):
+        return _cmp_impl(space, self, other, space.gt)
+
+    def ge__Array_ANY(space, self, other):
+        return _cmp_impl(space, self, other, space.ge)
+
     # Misc methods
 
     def buffer__Array(space, self):

File pypy/module/array/test/test_array.py

                 assert (a >= c) is False
                 assert (c >= a) is True
 
-                assert cmp(a, a) == 0
-                assert cmp(a, b) == 0
-                assert cmp(a, c) <  0
-                assert cmp(b, a) == 0
-                assert cmp(c, a) >  0
+                assert a == a
+                assert a == b
+                assert a < c
+                assert b == a
+                assert c > a
 
     def test_reduce(self):
         import pickle