Issue 3051: Let heapq work with either __lt__ or __le__.

This commit is contained in:
Raymond Hettinger 2008-06-11 12:06:49 +00:00
parent 4267be6478
commit f0bc3cbdc0
1 changed files with 6 additions and 7 deletions

View File

@ -17,13 +17,12 @@ static int
cmp_lt(PyObject *x, PyObject *y)
{
int cmp;
cmp = PyObject_RichCompareBool(x, y, Py_LT);
if (cmp == -1 && PyErr_ExceptionMatches(PyExc_AttributeError)) {
PyErr_Clear();
cmp = PyObject_RichCompareBool(y, x, Py_LE);
if (cmp != -1)
cmp = 1 - cmp;
}
if (PyObject_HasAttrString(x, "__lt__"))
return PyObject_RichCompareBool(x, y, Py_LT);
cmp = PyObject_RichCompareBool(y, x, Py_LE);
if (cmp != -1)
cmp = 1 - cmp;
return cmp;
}