Skip to content

gh-153357: Add object-oriented MinHeap and MaxHeap classes to heapq#153366

Closed
Twix1288 wants to merge 1 commit into
python:mainfrom
Twix1288:feature/heapq-oo-interface
Closed

gh-153357: Add object-oriented MinHeap and MaxHeap classes to heapq#153366
Twix1288 wants to merge 1 commit into
python:mainfrom
Twix1288:feature/heapq-oo-interface

Conversation

@Twix1288

@Twix1288 Twix1288 commented Jul 8, 2026

Copy link
Copy Markdown

This PR adds the MinHeap and MaxHeap classes to the heapq module to provide an object-oriented interface over the existing heap functions.

This resolves issue #153357.

Changes:

  • Added MinHeap and MaxHeap to Lib/heapq.py with __slots__ = ('_heap',) for memory efficiency.
  • Implemented push, pop, pushpop, and replace to delegate to the highly optimized underlying functions.
  • Added standard object methods including peek(), clear(), __len__(), __bool__(), __contains__(), __iter__(), and __repr__().
  • Comprehensive test suite updates in test_heapq.py using mixins to verify behavior against both pure Python (py_heapq) and C (c_heapq) underlying implementations.
  • Updated Doc/library/heapq.rst with class documentation and an explicit note about __iter__ and __repr__ yielding raw array elements rather than fully sorted output.

@Twix1288

Twix1288 commented Jul 8, 2026

Copy link
Copy Markdown
Author

This should work, let me know if any more information is needed!

@picnixz

picnixz commented Jul 8, 2026

Copy link
Copy Markdown
Member

There are plently of unrelated changes that should be removed. I would have also waited a bit more for the OP to reply. They may have wanted to do a PR themselves.

@Twix1288 Twix1288 force-pushed the feature/heapq-oo-interface branch from 744410a to ea5b53c Compare July 8, 2026 21:48
@bedevere-app

bedevere-app Bot commented Jul 8, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@Twix1288 Twix1288 force-pushed the feature/heapq-oo-interface branch from ea5b53c to 08ffd3b Compare July 8, 2026 22:01
@bedevere-app

bedevere-app Bot commented Jul 8, 2026

Copy link
Copy Markdown

Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool.

If this change has little impact on Python users, wait for a maintainer to apply the skip news label instead.

@StanFromIreland

Copy link
Copy Markdown
Member

The OP was also assigned to this, please check if someone is working on an issue before taking it on. Closing in favour of their patch.

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

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants