Author: Alex Gaynor <alex.gay...@gmail.com>
Branch: stdlib-2.7.8
Changeset: r73082:8b19227722ab
Date: 2014-08-27 07:58 -0700
http://bitbucket.org/pypy/pypy/changeset/8b19227722ab/

Log:    Replicate CPython's strange behavior in a vafguely reasonable way

diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -452,12 +452,6 @@
 
         # The real comparison
         if space.is_w(space.type(w_v), space.type(w_w)):
-            if (space.isinstance_w(w_v, space.w_set) or
-                    space.isinstance_w(w_v, space.w_frozenset)):
-                raise OperationError(
-                    space.w_TypeError,
-                    space.wrap("cannot compare sets using cmp()")
-                )
             # for object of the same type, prefer __cmp__ over rich comparison.
             w_cmp = space.lookup(w_v, '__cmp__')
             w_res = _invoke_binop(space, w_cmp, w_v, w_w)
diff --git a/pypy/objspace/std/setobject.py b/pypy/objspace/std/setobject.py
--- a/pypy/objspace/std/setobject.py
+++ b/pypy/objspace/std/setobject.py
@@ -168,6 +168,14 @@
             w_currently_in_repr = ec._py_repr = space.newdict()
         return setrepr(space, w_currently_in_repr, self)
 
+    def descr_cmp(self, space, w_other):
+        if space.is_w(space.type(self), space.type(w_other)):
+            # hack hack until we get the expected result
+            raise OperationError(space.w_TypeError,
+                    space.wrap('cannot compare sets using cmp()'))
+        else:
+            return space.w_NotImplemented
+
     def descr_eq(self, space, w_other):
         if isinstance(w_other, W_BaseSetObject):
             return space.wrap(self.equals(w_other))
@@ -514,6 +522,7 @@
     __init__ = gateway.interp2app(W_BaseSetObject.descr_init),
     __repr__ = gateway.interp2app(W_BaseSetObject.descr_repr),
     __hash__ = None,
+    __cmp__ = gateway.interp2app(W_BaseSetObject.descr_cmp),
 
     # comparison operators
     __eq__ = gateway.interp2app(W_BaseSetObject.descr_eq),
@@ -613,6 +622,7 @@
     __new__ = gateway.interp2app(W_FrozensetObject.descr_new2),
     __repr__ = gateway.interp2app(W_BaseSetObject.descr_repr),
     __hash__ = gateway.interp2app(W_FrozensetObject.descr_hash),
+    __cmp__ = gateway.interp2app(W_BaseSetObject.descr_cmp),
 
     # comparison operators
     __eq__ = gateway.interp2app(W_BaseSetObject.descr_eq),
_______________________________________________
pypy-commit mailing list
pypy-commit@python.org
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to