mirror of
https://github.com/python/cpython
synced 2026-09-29 11:35:29 +03:00
By default, != returns the opposite of ==, unless the latter returns
NotImplemented. (Is this worth backporting to 2.6? It seems so useful...!)
This commit is contained in:
parent
a4335b1e6b
commit
e27dc72308
3 changed files with 25 additions and 1 deletions
|
|
@ -2314,7 +2314,22 @@ object_richcompare(PyObject *self, PyObject *other, int op)
|
|||
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:
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue