Author: Philip Jenvey <[email protected]>
Branch: py3k
Changeset: r58792:1e4f11518e59
Date: 2012-11-08 12:10 -0800
http://bitbucket.org/pypy/pypy/changeset/1e4f11518e59/
Log: always try the right side comparison even when the types match
exactly
diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -548,23 +548,16 @@
w_left_src, w_left_impl = space.lookup_in_type_where(w_typ1, left)
w_first = w_obj1
w_second = w_obj2
- #
- if left == right and space.is_w(w_typ1, w_typ2):
- # for __eq__ and __ne__, if the objects have the same
- # class, then don't try the opposite method, which is the
- # same one.
- w_right_impl = None
- else:
- # in all other cases, try the opposite method.
- w_right_src, w_right_impl =
space.lookup_in_type_where(w_typ2,right)
- if space.is_w(w_typ1, w_typ2):
- # if the type is the same, then don't reverse: try
- # left first, right next.
- pass
- elif space.is_true(space.issubtype(w_typ2, w_typ1)):
- # if typ2 is a subclass of typ1.
- w_obj1, w_obj2 = w_obj2, w_obj1
- w_left_impl, w_right_impl = w_right_impl, w_left_impl
+
+ w_right_src, w_right_impl = space.lookup_in_type_where(w_typ2,right)
+ if space.is_w(w_typ1, w_typ2):
+ # if the type is the same, then don't reverse: try
+ # left first, right next.
+ pass
+ elif space.is_true(space.issubtype(w_typ2, w_typ1)):
+ # if typ2 is a subclass of typ1.
+ w_obj1, w_obj2 = w_obj2, w_obj1
+ w_left_impl, w_right_impl = w_right_impl, w_left_impl
w_res = _invoke_binop(space, w_left_impl, w_obj1, w_obj2)
if w_res is not None:
diff --git a/pypy/objspace/test/test_descroperation.py
b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -538,6 +538,17 @@
assert (D() > A()) == 'D:A.gt'
assert (D() >= A()) == 'D:A.ge'
+ def test_binop_rule(self):
+ called = []
+ class A:
+ def __eq__(self, other):
+ called.append(self)
+ return NotImplemented
+ a1 = A()
+ a2 = A()
+ a1 == a2
+ assert called == [a1, a2]
+
def test_addition(self):
class A:
def __init__(self, a):
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit