Skip to content

Commit 8fd1a03

Browse files
Clean up and add missing
1 parent 3561206 commit 8fd1a03

File tree

2 files changed

+15
-6
lines changed

2 files changed

+15
-6
lines changed

Doc/whatsnew/3.14.rst

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -567,16 +567,13 @@ getopt
567567
heapq
568568
-----
569569

570-
* The max-heap functions in :mod:`heapq` are now public:
570+
* Add functions for working with max-heaps:
571571

572572
* :func:`heapq.heapify_max`,
573573
* :func:`heapq.heappush_max`,
574574
* :func:`heapq.heappop_max`,
575575
* :func:`heapq.heapreplace_max`
576-
577-
Previous underscored naming is kept for backwards compatibility.
578-
Additionally, the missing function :func:`heapq.heappushpop_max` has been added to both the C and Python
579-
implementations.
576+
* :func:`heapq.heappushpop_max`
580577

581578

582579
http

Lib/test/test_heapq.py

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -459,7 +459,8 @@ def test_cmp_err(self):
459459
seq = [CmpErr(), CmpErr(), CmpErr()]
460460
for f in (self.module.heapify, self.module.heappop):
461461
self.assertRaises(ZeroDivisionError, f, seq)
462-
for f in (self.module.heappush, self.module.heapreplace):
462+
for f in (self.module.heappush, self.module.heapreplace,
463+
self.module.heappush_max, self.module.heapreplace_max):
463464
self.assertRaises(ZeroDivisionError, f, seq, 10)
464465
for f in (self.module.nlargest, self.module.nsmallest):
465466
self.assertRaises(ZeroDivisionError, f, 2, seq)
@@ -541,6 +542,17 @@ def __lt__(self, o):
541542
self.assertRaises((IndexError, RuntimeError), self.module.heappush, list1, g(1))
542543
self.assertRaises((IndexError, RuntimeError), self.module.heappush, list2, h(1))
543544

545+
list1, list2 = [], []
546+
547+
self.module.heappush_max(list1, h(0))
548+
self.module.heappush_max(list2, g(0))
549+
self.module.heappush_max(list1, g(1))
550+
self.module.heappush_max(list2, h(1))
551+
552+
TestHeap.check_max_invariant(self, list1)
553+
TestHeap.check_max_invariant(self, list2)
554+
555+
544556
class TestErrorHandlingPython(TestErrorHandling, TestCase):
545557
module = py_heapq
546558

0 commit comments

Comments
 (0)