[Python-Dev] Re: heapq method names

Tim Peters tim.one@comcast.net
Mon, 26 Aug 2002 12:47:35 -0400

[Raymond Hettinger, on
 import heapq

 class Heap(list):
     def __init__(self, iterable=[]):
     push    = heapq.heappush
     popmin  = heapq.heappop
     replace = heapq.heapreplace
     heapify = heapq.heapify

> And perhaps:
>    def __iter__(self):
>        while True:
>             yield self.popmin()

If we were trying to hide the list nature, yes, but I don't think so if the
intent is that a heapq heap *is* a list with a few extra methods.  For
example, I know I've already done


at least once for a Heap of this type, with the list meaning in mind, and it
would have been at best irritating if that had emptied the heap as a side
effect.  Renaming __iter__ to heapiter would be cool, though!