[Python-Dev] Re: heapq method names

Jeremy Hylton jeremy@alum.mit.edu
Mon, 26 Aug 2002 09:08:05 -0400


>>>>> "TP" == Tim Peters <tim.one@comcast.net> writes:

  TP> That is, it creates a Heap type that's just a list with some
  TP> extra methods.  Note that the "pop" method can't be named "pop"!
  TP> If you try, you'll soon get unbounded recursion because the
  TP> heapq functions need list.pop to access the list meaning of
  TP> "pop".

  TP> Guido suggested a long time ago that such a class could be added
  TP> to heapq, and I like it a lot in real life.

You can't use all of the regular list methods, right?  If I'd called
append() an a Heap(), it wouldn't maintain the heap invariant.  I
would think the same is true of insert() and lots of other methods.
If we add a Heap class, which seems quite handy, maybe we should
disable methods that don't work.

Interesting to note that if you disable the invalid methods of list,
then you've got a subclass of list that is not a subtype.

Jeremy