Martin Panter added the comment:

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

----------
nosy: +vadmium
resolution:  -> not a bug
status: open -> closed

_______________________________________
Python tracker <rep...@bugs.python.org>
<http://bugs.python.org/issue24660>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to