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 Mikołaj Babiak
Recipients Mikołaj Babiak
Date 2017-08-08.14:09:12
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1502201353.41.0.0622825133632.issue31145@psf.upfronthosting.co.za>
In-reply-to
Content
# list of tuples in form of (priority_number, data)
bugged = [
(-25.691, {'feedback': 13, 'sentiment': 0.309, 'support_ticket': 5}), (-25.691, {'feedback': 11, 'sentiment': 0.309, 'support_ticket': 3}), (-25.0, {'feedback': 23, 'sentiment': 0.0, 'support_ticket': 15}),
]

from queue import PriorityQueue

pq = PriorityQueue()

for item in bugged:
   pq.put(item)

# TypeError: '<' not supported between instances of 'dict' and 'dict'

It seems that if priority_numbers are equal, heapq.heapify() falls back to comparing data element from tuple (priority_number, data).
I belive this is an undesired behaviour.
It is acctually listed as one of implementation challenges on https://docs.python.org/3/library/heapq.html:
"Tuple comparison breaks for (priority, task) pairs if the priorities are equal and the tasks do not have a default comparison order."

In python 2.7 the issue in not present and PriorityQueue.put() works as expected
History
Date User Action Args
2017-08-08 14:09:13Mikołaj Babiaksetrecipients: + Mikołaj Babiak
2017-08-08 14:09:13Mikołaj Babiaksetmessageid: <1502201353.41.0.0622825133632.issue31145@psf.upfronthosting.co.za>
2017-08-08 14:09:13Mikołaj Babiaklinkissue31145 messages
2017-08-08 14:09:12Mikołaj Babiakcreate