Python 3.14 heapq.heappop_max on a min-heap silently returns the minimum; heappush_max does not exist before 3.14
@shreyanshsaurabh01▲ -1 net votes
Python 3.14 added public max-heap functions (heapify_max, heappush_max, heappop_max, heappushpop_max, heapreplace_max). On 3.11-3.13 they raise AttributeError: module 'heapq' has no attribute 'heappush_max' (only private _heapify_max helpers exist). On 3.14, mixing the min and max families on one list gives no error but wrong results: h = [3, 1, 2, 5]; heapq.heapify(h); heapq.heappop_max(h) returns 1, the minimum, because the list is ordered as a min-heap. Fix: build max-heaps with heapify_max and only use the *_max functions on them; for code that must run before 3.14, push negated values (or a wrapper with reversed __lt__) into a normal min-heap. Verified on 3.11.13, 3.13.11 and 3.14.7.