From 954ee801f3102b0bf8afadb933c118430b9d5b38 Mon Sep 17 00:00:00 2001 From: Thiago Perrotta Date: Sun, 11 Jan 2026 08:54:03 -0300 Subject: [PATCH] Add undocumented _heappop_max and _heapreplace_max to heapq stubs MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Verify these methods exist: ``` ❯ python3 Python 3.9.6 (default, Dec 2 2025, 07:27:58) [Clang 17.0.0 (clang-1700.6.3.2)] on darwin Type "help", "copyright", "credits" or "license" for more information. >>> import heapq >>> dir(heapq) ['__about__', '__all__', '__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_heapify_max', '_heappop_max', '_heapreplace_max', '_siftdown', '_siftdown_max', '_siftup', '_siftup_max', 'heapify', 'heappop', 'heappush', 'heappushpop', 'heapreplace', 'merge', 'nlargest', 'nsmallest'] ``` Arguably the proper fix is: ```diff -def _heapify_max(heap: list[Any], /) -> None: ... # undocumented +def _heapify_max(heap: Iterable[_S], /) -> None: ... # undocumented +def _heappop_max(heap: Iterable[_S], /) -> _S: ... # undocumented +def _heapreplace_max(heap: Iterable[_S], item: _S, /) -> _S: ... # undocumented ``` Opt in for consistency with the pre-existing `_heapify_max` though. --- stdlib/heapq.pyi | 2 ++ 1 file changed, 2 insertions(+) diff --git a/stdlib/heapq.pyi b/stdlib/heapq.pyi index ff8ba7ff1f82..723e2d0e1e8d 100644 --- a/stdlib/heapq.pyi +++ b/stdlib/heapq.pyi @@ -20,3 +20,5 @@ def merge( def nlargest(n: int, iterable: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = None) -> list[_S]: ... def nsmallest(n: int, iterable: Iterable[_S], key: Callable[[_S], SupportsRichComparison] | None = None) -> list[_S]: ... def _heapify_max(heap: list[Any], /) -> None: ... # undocumented +def _heappop_max(heap: list[Any], /) -> Any: ... # undocumented +def _heapreplace_max(heap: list[Any], item: Any, /) -> Any: ... # undocumented