Raymond Hettinger added the comment: I don't see any way to change PriorityQueue to fix this. The non-comparability of dicts likely won't be restored, nor will the lexicographic comparison order of tuples be likely to change.
One possible way forward is to provide a wrapper with the desired comparison behavior: pq = PriorityQueue() pq.put(Prioritize(13, task)) task = pq.get().item where Prioritize is implemented something like this: import functools @functools.total_ordering class Prioritize: def __init__(self, priority, item): self.priority = priority self.item = item def __eq__(self, other): return self.priority == other.priority def __lt__(self, other): return self.priority < other.priority from queue import PriorityQueue, Empty from contextlib import suppress 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}), ] pq = PriorityQueue() for priority, item in bugged: pq.put(Prioritize(priority, item)) with suppress(Empty): while True: item = pq.get_nowait().item print(item) ---------- assignee: -> rhettinger nosy: +rhettinger type: behavior -> enhancement versions: +Python 3.7 -Python 3.6 _______________________________________ Python tracker <rep...@bugs.python.org> <http://bugs.python.org/issue31145> _______________________________________ _______________________________________________ Python-bugs-list mailing list Unsubscribe: https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com