]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue 3051: Let heapq work with either __lt__ or __le__.
authorRaymond Hettinger <python@rcn.com>
Wed, 11 Jun 2008 12:06:49 +0000 (12:06 +0000)
committerRaymond Hettinger <python@rcn.com>
Wed, 11 Jun 2008 12:06:49 +0000 (12:06 +0000)
Modules/_heapqmodule.c

index 7a6416155d736606e63b452bceba719ec55af7d1..8edf626effd69aa24564afd40c5b03ce8e9d147b 100644 (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;
 }