Issue #4296: Fix PyObject_RichCompareBool so that "x in [x]" evaluates to
True, even when x doesn't compare equal to itself. This was a regression
from 2.6.
Reviewed by R. Hettinger and C. Heimes.
diff --git a/Objects/object.c b/Objects/object.c
index cdbceaf..2c43221 100644
--- a/Objects/object.c
+++ b/Objects/object.c
@@ -687,6 +687,15 @@
PyObject *res;
int ok;
+ /* Quick result when objects are the same.
+ Guarantees that identity implies equality. */
+ if (v == w) {
+ if (op == Py_EQ)
+ return 1;
+ else if (op == Py_NE)
+ return 0;
+ }
+
res = PyObject_RichCompare(v, w, op);
if (res == NULL)
return -1;