bpo-37648: Fixed minor inconsistency in some __contains__. (GH-14904)

The collection's item is now always at the left and
the needle is on the right of ==.
This commit is contained in:
Serhiy Storchaka 2019-08-04 14:12:48 +03:00 committed by GitHub
parent 17e52649c0
commit 18b711c5a7
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
12 changed files with 86 additions and 22 deletions

View file

@ -2016,7 +2016,7 @@ _PySequence_IterSearch(PyObject *seq, PyObject *obj, int operation)
break;
}
cmp = PyObject_RichCompareBool(obj, item, Py_EQ);
cmp = PyObject_RichCompareBool(item, obj, Py_EQ);
Py_DECREF(item);
if (cmp < 0)
goto Fail;

View file

@ -4392,7 +4392,7 @@ dictitems_contains(_PyDictViewObject *dv, PyObject *obj)
return 0;
}
Py_INCREF(found);
result = PyObject_RichCompareBool(value, found, Py_EQ);
result = PyObject_RichCompareBool(found, value, Py_EQ);
Py_DECREF(found);
return result;
}

View file

@ -449,8 +449,7 @@ list_contains(PyListObject *a, PyObject *el)
int cmp;
for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
cmp = PyObject_RichCompareBool(el, PyList_GET_ITEM(a, i),
Py_EQ);
cmp = PyObject_RichCompareBool(PyList_GET_ITEM(a, i), el, Py_EQ);
return cmp;
}

View file

@ -403,8 +403,7 @@ tuplecontains(PyTupleObject *a, PyObject *el)
int cmp;
for (i = 0, cmp = 0 ; cmp == 0 && i < Py_SIZE(a); ++i)
cmp = PyObject_RichCompareBool(el, PyTuple_GET_ITEM(a, i),
Py_EQ);
cmp = PyObject_RichCompareBool(PyTuple_GET_ITEM(a, i), el, Py_EQ);
return cmp;
}