[Python-checkins] r64116 - python/trunk/Modules/_heapqmodule.c
raymond.hettinger
python-checkins at python.org
Wed Jun 11 14:06:50 CEST 2008
Author: raymond.hettinger
Date: Wed Jun 11 14:06:49 2008
New Revision: 64116
Log:
Issue 3051: Let heapq work with either __lt__ or __le__.
Modified:
python/trunk/Modules/_heapqmodule.c
Modified: python/trunk/Modules/_heapqmodule.c
==============================================================================
--- python/trunk/Modules/_heapqmodule.c (original)
+++ python/trunk/Modules/_heapqmodule.c Wed Jun 11 14:06:49 2008
@@ -17,13 +17,12 @@
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;
}
More information about the Python-checkins
mailing list