[Python-ideas] Adding a thin wrapper class around the functions in stdlib.heapq

Antoine Pitrou solipsis at pitrou.net
Wed Nov 22 06:09:23 EST 2017


On Wed, 22 Nov 2017 00:22:00 -0600
Nick Timkovich <prometheus235 at gmail.com>
wrote:
> 
> Functions are great. I'm a big fan of functions. However,
> 
> 1. Once there are several that all have the same thing as an argument:
> thing_operation1(thing, arg), thing_operation2(thing, arg)...it's about
> time to bind them together.
> 2. And especially for the heap "soft-datatype": once it's heapified,
> naively modifying it with other methods will ruin the heap invariant. **The
> actual list you pass around can't be treated as a list.**

A third reason: documentation and discoverability.  If I type
help(some_heapified_list) at the prompt, I get the usual documentation
for list methods, not the documentation of heapq functions...

Regards

Antoine.




More information about the Python-ideas mailing list