gh-136017: avoid decref in rich compare for bool objects (#136018)

This commit is contained in:
Pieter Eendebak 2025-06-27 11:01:51 +02:00 committed by GitHub
parent 07183ebce3
commit e23518fa96
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -1131,11 +1131,14 @@ PyObject_RichCompareBool(PyObject *v, PyObject *w, int op)
res = PyObject_RichCompare(v, w, op);
if (res == NULL)
return -1;
if (PyBool_Check(res))
if (PyBool_Check(res)) {
ok = (res == Py_True);
else
assert(_Py_IsImmortal(res));
}
else {
ok = PyObject_IsTrue(res);
Py_DECREF(res);
Py_DECREF(res);
}
return ok;
}