diff --git a/Cython/Compiler/ModuleNode.py b/Cython/Compiler/ModuleNode.py index 0b7981deb4fec9448ce85cbfff8d937b67376fb1..a8f620df5d251f06734e8b8b8603d692046f83a4 100644 --- a/Cython/Compiler/ModuleNode.py +++ b/Cython/Compiler/ModuleNode.py @@ -1830,17 +1830,20 @@ class ModuleNode(Nodes.Node, Nodes.BlockNode): code.putln("case Py_%s: {" % cmp_type) if cmp_method == '__eq__': eq_entry = entry - code.putln("if (o1 == o2) return __Pyx_NewRef(Py_True);") + # Python itself does not do this optimisation, it seems... + #code.putln("if (o1 == o2) return __Pyx_NewRef(Py_True);") elif cmp_method == '__ne__': has_ne = True - code.putln("if (o1 == o2) return __Pyx_NewRef(Py_False);") + # Python itself does not do this optimisation, it seems... + #code.putln("if (o1 == o2) return __Pyx_NewRef(Py_False);") code.putln("return %s(o1, o2);" % entry.func_cname) code.putln("}") if eq_entry and not has_ne and not extern_parent: code.putln("case Py_NE: {") code.putln("PyObject *ret;") - code.putln("if (o1 == o2) return __Pyx_NewRef(Py_False);") + # Python itself does not do this optimisation, it seems... + #code.putln("if (o1 == o2) return __Pyx_NewRef(Py_False);") code.putln("ret = %s(o1, o2);" % eq_entry.func_cname) code.putln("if (likely(ret && ret != Py_NotImplemented)) {") code.putln("int b = __Pyx_PyObject_IsTrue(ret); Py_DECREF(ret);") diff --git a/tests/run/ext_auto_richcmp.py b/tests/run/ext_auto_richcmp.py index 9bd77f29c29c5427098fdd3fd4ef6c4731be8b0c..ef42856f95749140e4f7532b95552c354c832617 100644 --- a/tests/run/ext_auto_richcmp.py +++ b/tests/run/ext_auto_richcmp.py @@ -424,3 +424,21 @@ class ClassLtGt(X): if isinstance(other, X): return self.x > other.x return NotImplemented + + +@cython.cclass +class List(list): + """ + >>> l = [1, 2, 3, 4] + >>> notl = List(l) + >>> notl == l + False + >>> notl != l # implemented by base type + False + >>> notl == notl + True + >>> notl != notl # implemented by base type + False + """ + def __eq__(self, other): + return self is other or list(self) != list(other)