diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py index 33a55f76d9b..3c8d82958fd 100644 --- a/Lib/test/test_list.py +++ b/Lib/test/test_list.py @@ -225,6 +225,8 @@ class ListTest(list_tests.CommonTest): # to list elements while calling PyObject_RichCompareBool(). lst = [X(), X()] 3 in lst + lst = [X(), X()] + X() in lst if __name__ == "__main__": diff --git a/Objects/listobject.c b/Objects/listobject.c index 38055d5f5f3..2c07ceb0d41 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -452,7 +452,7 @@ list_contains(PyListObject *a, PyObject *el) for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i) { item = PyList_GET_ITEM(a, i); Py_INCREF(item); - cmp = PyObject_RichCompareBool(PyList_GET_ITEM(a, i), el, Py_EQ); + cmp = PyObject_RichCompareBool(item, el, Py_EQ); Py_DECREF(item); } return cmp;