Commit f0bc3cbd authored by Raymond Hettinger's avatar Raymond Hettinger

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

parent 4267be64
...@@ -17,13 +17,12 @@ static int ...@@ -17,13 +17,12 @@ static int
cmp_lt(PyObject *x, PyObject *y) cmp_lt(PyObject *x, PyObject *y)
{ {
int cmp; int cmp;
cmp = PyObject_RichCompareBool(x, y, Py_LT);
if (cmp == -1 && PyErr_ExceptionMatches(PyExc_AttributeError)) { if (PyObject_HasAttrString(x, "__lt__"))
PyErr_Clear(); return PyObject_RichCompareBool(x, y, Py_LT);
cmp = PyObject_RichCompareBool(y, x, Py_LE); cmp = PyObject_RichCompareBool(y, x, Py_LE);
if (cmp != -1) if (cmp != -1)
cmp = 1 - cmp; cmp = 1 - cmp;
}
return cmp; return cmp;
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment