This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author martin.panter
Recipients josh.r, martin.panter, socketpair
Date 2015-07-18.13:00:10
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1437224410.92.0.0862015977593.issue24660@psf.upfronthosting.co.za>
In-reply-to
Content
I can’t compare non-partial functions either. How did your first heapify() call succeed?

Python 3.4.3 (default, Mar 25 2015, 17:13:50) 
[GCC 4.9.2 20150304 (prerelease)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import heapq
>>> from functools import partial
>>> qwe = [(0, lambda x: 42), (0, lambda x: 56)]
>>> heapq.heapify(qwe)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: function() < function()
>>> (lambda x: 42) < (lambda x: 56)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: unorderable types: function() < function()

This is not a problem specific to “heapq”. This is how function objects, lambda objects, bound class methods, etc, are meant to work. Python doesn’t implement ordering comparisons for them. This is kind of explained at <https://docs.python.org/dev/reference/expressions.html#comparisons>. See Issue 12067 if you want to help improve this section of the documentation.

If you don’t care about the order, perhaps you could ensure the first item in each tuple is unique, or add a dummy item in the middle that ensures the tuples have a definite order:

>>> (0, 0, lambda x: 42) < (0, 1, lambda x: 56)
True
History
Date User Action Args
2015-07-18 13:00:10martin.pantersetrecipients: + martin.panter, socketpair, josh.r
2015-07-18 13:00:10martin.pantersetmessageid: <1437224410.92.0.0862015977593.issue24660@psf.upfronthosting.co.za>
2015-07-18 13:00:10martin.panterlinkissue24660 messages
2015-07-18 13:00:10martin.pantercreate