[pypy-commit] pypy default: Fix issue 2352 regarding __eq__'s arguments order in list.find().
gbleu
pypy.commits at gmail.com
Sat Jul 23 10:34:35 EDT 2016
Author: touilleMan <emmanuel.leblond at gmail.com>
Branch:
Changeset: r85824:4bd027dc94a2
Date: 2016-07-23 16:06 +0200
http://bitbucket.org/pypy/pypy/changeset/4bd027dc94a2/
Log: Fix issue 2352 regarding __eq__'s arguments order in list.find().
diff --git a/pypy/objspace/std/listobject.py b/pypy/objspace/std/listobject.py
--- a/pypy/objspace/std/listobject.py
+++ b/pypy/objspace/std/listobject.py
@@ -795,7 +795,7 @@
tp = space.type(w_item)
while i < stop and i < w_list.length():
find_jmp.jit_merge_point(tp=tp)
- if space.eq_w(w_list.getitem(i), w_item):
+ if space.eq_w(w_item, w_list.getitem(i)):
return i
i += 1
raise ValueError
diff --git a/pypy/objspace/std/test/test_listobject.py b/pypy/objspace/std/test/test_listobject.py
--- a/pypy/objspace/std/test/test_listobject.py
+++ b/pypy/objspace/std/test/test_listobject.py
@@ -503,6 +503,34 @@
assert not l.__contains__(-20)
assert not l.__contains__(-21)
+ logger = []
+
+ class Foo(object):
+
+ def __init__(self, value, name=None):
+ self.value = value
+ self.name = name or value
+
+ def __repr__(self):
+ return '<Foo %s>' % self.name
+
+ def __eq__(self, other):
+ logger.append((self, other))
+ return self.value == other.value
+
+ foo1, foo2, foo3 = Foo(1), Foo(2), Foo(3)
+ foo42 = Foo(42)
+ foo_list = [foo1, foo2, foo3]
+ foo42 in foo_list
+ logger_copy = logger[:] # prevent re-evaluation during pytest error print
+ assert logger_copy == [(foo42, foo1), (foo42, foo2), (foo42, foo3)]
+
+ del logger[:]
+ foo2_bis = Foo(2, '2 bis')
+ foo2_bis in foo_list
+ logger_copy = logger[:] # prevent re-evaluation during pytest error print
+ assert logger_copy == [(foo2_bis, foo1), (foo2_bis, foo2)]
+
def test_call_list(self):
assert list('') == []
assert list('abc') == ['a', 'b', 'c']
More information about the pypy-commit
mailing list