New submission from Mikołaj Babiak:

# 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:

# 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
"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

components: Library (Lib)
messages: 299922
nosy: Mikołaj Babiak
priority: normal
severity: normal
status: open
title: PriorityQueue.put() fails with TypeError if priority_number in tuples of 
(priority_number, data) are the same.
type: behavior
versions: Python 3.6

Python tracker <>
Python-bugs-list mailing list

Reply via email to