mirror of
https://github.com/python/cpython.git
synced 2025-08-03 08:34:29 +00:00
Issue #21408: The default __ne__() now returns NotImplemented if __eq__()
returned NotImplemented. Removed incorrect implementations of __ne__().
This commit is contained in:
commit
34af5023fc
11 changed files with 77 additions and 47 deletions
|
@ -3385,9 +3385,14 @@ object_richcompare(PyObject *self, PyObject *other, int op)
|
|||
break;
|
||||
|
||||
case Py_NE:
|
||||
/* By default, != returns the opposite of ==,
|
||||
/* By default, __ne__() delegates to __eq__() and inverts the result,
|
||||
unless the latter returns NotImplemented. */
|
||||
res = PyObject_RichCompare(self, other, Py_EQ);
|
||||
if (self->ob_type->tp_richcompare == NULL) {
|
||||
res = Py_NotImplemented;
|
||||
Py_INCREF(res);
|
||||
break;
|
||||
}
|
||||
res = (*self->ob_type->tp_richcompare)(self, other, Py_EQ);
|
||||
if (res != NULL && res != Py_NotImplemented) {
|
||||
int ok = PyObject_IsTrue(res);
|
||||
Py_DECREF(res);
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue