[docs] Code example bug in Heap page

Nicolas Gleichgerrcht nicog89 at gmail.com
Wed Jun 1 05:02:12 CEST 2011


Hello, I thing there is a bug in the heapq page
(http://docs.python.org/library/heapq.html) under the 8.4.2. Priority
Queue Implementation Notes Secction.
In the code example defines this function

def get_top_priority():
    while True:
        priority, count, task = heappop(pq)
        del task_finder[task]
        if count is not INVALID:
            return task

I thing the delete must be inside the if statment, because if you have
reprioritize task, with lower priority than before, it will delete
from task_finder, but the a task will still be in pq heap.

Example:
add_task(2, 'a')
add_task(1,'b')
reprioritize(3, 'a')
get_top_priority() #print b
get_top_priority() #rise Error, but shoud print b

Thanks!


More information about the docs mailing list