-
-
Notifications
You must be signed in to change notification settings - Fork 33.2k
Closed
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
Bug report
Bug description:
Read the code below:
import heapq
heap = []
heapq.heappush(heap, (2, 2))
heapq.heappush(heap, (1, 2))
heapq.heappush(heap, (1, -1))
print(heap)
It is very simple, and obviously, it should print "[(1, -1), (1, 2), (2, 2)]".
But here is what it prints:
PC-Killer@nixos ~> python --version ; cat -n ~/python_work/bugs/unordered_heap.py ; python ~/python_work/bugs/unordered_heap.py
Python 3.14.0a4
1 import heapq
2
3
4 heap = []
5 heapq.heappush(heap, (2, 2))
6 heapq.heappush(heap, (1, 2))
7 heapq.heappush(heap, (1, -1))
8 print(heap)
[(1, -1), (2, 2), (1, 2)]
The heap became unsorted.
CPython versions tested on:
3.14
Operating systems tested on:
Linux
Metadata
Metadata
Assignees
Labels
type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error