Author: Philip Jenvey <[email protected]>
Branch: 
Changeset: r74188:5ecbc7d29c83
Date: 2014-10-24 12:41 -0700
http://bitbucket.org/pypy/pypy/changeset/5ecbc7d29c83/

Log:    o fix __ne__ not handling floats like __eq__ o match CPython's
        TypeError behavior w/ rich comparisons & number types

diff --git a/pypy/objspace/std/complexobject.py 
b/pypy/objspace/std/complexobject.py
--- a/pypy/objspace/std/complexobject.py
+++ b/pypy/objspace/std/complexobject.py
@@ -412,16 +412,20 @@
             return space.newbool((self.realval != w_other.realval) or
                                  (self.imagval != w_other.imagval))
         if (space.isinstance_w(w_other, space.w_int) or
-            space.isinstance_w(w_other, space.w_long)):
+            space.isinstance_w(w_other, space.w_long) or
+            space.isinstance_w(w_other, space.w_float)):
             if self.imagval:
                 return space.w_True
             return space.ne(space.newfloat(self.realval), w_other)
         return space.w_NotImplemented
 
     def _fail_cmp(self, space, w_other):
-        if isinstance(w_other, W_ComplexObject):
+        if (isinstance(w_other, W_ComplexObject) or
+            space.isinstance_w(w_other, space.w_int) or
+            space.isinstance_w(w_other, space.w_long) or
+            space.isinstance_w(w_other, space.w_float)):
             raise oefmt(space.w_TypeError,
-                        "cannot compare complex numbers using <, <=, >, >=")
+                        "no ordering relation is defined for complex numbers")
         return space.w_NotImplemented
 
     def descr_add(self, space, w_rhs):
diff --git a/pypy/objspace/std/test/test_complexobject.py 
b/pypy/objspace/std/test/test_complexobject.py
--- a/pypy/objspace/std/test/test_complexobject.py
+++ b/pypy/objspace/std/test/test_complexobject.py
@@ -180,6 +180,14 @@
         assert (5+0j) != large
         assert large != (5+0j)
 
+    def test_richcompare_numbers(self):
+        for n in 8, 8L, 0.01:
+            assert complex.__eq__(n+0j, n)
+            assert not complex.__ne__(n+0j, n)
+            assert not complex.__eq__(complex(n, n), n)
+            assert complex.__ne__(complex(n, n), n)
+            raises(TypeError, complex.__lt__, n+0j, n)
+
     def test_richcompare_boundaries(self):
         z = 9007199254740992+0j
         i = 9007199254740993
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to