NotImplemented.
(Is this worth backporting to 2.6? It seems so useful...!)
self.assertEqual(a == b, id(a) == id(b),
'a=%r, b=%r' % (a, b))
+ def test_ne_defaults_to_not_eq(self):
+ a = Cmp(1)
+ b = Cmp(1)
+ self.assertTrue(a == b)
+ self.assertFalse(a != b)
+
def test_main():
test_support.run_unittest(ComparisonTest)
Core and Builtins
-----------------
+- By default, != returns the opposite of ==, unless the latter returns
+ NotImplemented.
+
- Patch #1680961: sys.exitfunc has been removed and replaced with a private
C-level API.
break;
case Py_NE:
- res = (self != other) ? Py_True : Py_False;
+ /* By default, != returns the opposite of ==,
+ unless the latter returns NotImplemented. */
+ res = PyObject_RichCompare(self, other, Py_EQ);
+ if (res != NULL && res != Py_NotImplemented) {
+ int ok = PyObject_IsTrue(res);
+ Py_DECREF(res);
+ if (ok < 0)
+ res = NULL;
+ else {
+ if (ok)
+ res = Py_False;
+ else
+ res = Py_True;
+ Py_INCREF(res);
+ }
+ }
break;
default: