Skip to content

Can we provide a object oriented wrapper to Heap's primary functions? #143326

Closed as not planned

Description

@RikidWai

Feature or enhancement

Proposal:

The heapq module provides an efficient and flexible heap implementation, I would like to start a discussion about whether the standard library could benefit from an optional, lightweight object-oriented wrapper around heapq, similar to collections.deque or collections.Counter.

For example, instead of:

h = []
heappush(h, (5, 'write code'))
heappush(h, (7, 'release product'))
heappop(h)

a wrapper might allow:

h = Heap()
h.push((5, 'write code'))
h.push((7, 'release product'))
h.pop()

This could:

  • improve readability,
  • provide a non-threaded alternative to queue.PriorityQueue.

I would be happy to contribute an implementation or prototype if the idea has merit.

Has this already been discussed elsewhere?

No response given

Links to previous discussion of this feature:

No response

Activity

  1. picnixz commented on Jan 1, 2026

    @picnixz
    Member

    Please discuss this on https://discuss.python.org/c/ideas/6 first.

  2. ronaldoussoren commented on Jan 1, 2026

    @ronaldoussoren
    Contributor

    This issue duplicates #57951 and #62034 from years ago. The former has a draft patch for adding a Heap class.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions