Message299922
# 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 |
|
Date |
User |
Action |
Args |
2017-08-08 14:09:13 | Mikołaj Babiak | set | recipients:
+ Mikołaj Babiak |
2017-08-08 14:09:13 | Mikołaj Babiak | set | messageid: <1502201353.41.0.0622825133632.issue31145@psf.upfronthosting.co.za> |
2017-08-08 14:09:13 | Mikołaj Babiak | link | issue31145 messages |
2017-08-08 14:09:12 | Mikołaj Babiak | create | |
|