Skip to content

Commit d73534b

Browse files
add rich comparison bound to heapq and priorityqueues using heapq (#14419)
1 parent 84e41f2 commit d73534b

File tree

3 files changed

+9
-8
lines changed

3 files changed

+9
-8
lines changed

stdlib/_heapq.pyi

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,17 @@
11
import sys
2-
from typing import Any, Final, TypeVar
3-
4-
_T = TypeVar("_T") # list items must be comparable
2+
from _typeshed import SupportsRichComparisonT as _T # All type variable use in this module requires comparability.
3+
from typing import Final
54

65
__about__: Final[str]
76

8-
def heapify(heap: list[Any], /) -> None: ... # list items must be comparable
7+
def heapify(heap: list[_T], /) -> None: ...
98
def heappop(heap: list[_T], /) -> _T: ...
109
def heappush(heap: list[_T], item: _T, /) -> None: ...
1110
def heappushpop(heap: list[_T], item: _T, /) -> _T: ...
1211
def heapreplace(heap: list[_T], item: _T, /) -> _T: ...
1312

1413
if sys.version_info >= (3, 14):
15-
def heapify_max(heap: list[Any], /) -> None: ... # list items must be comparable
14+
def heapify_max(heap: list[_T], /) -> None: ...
1615
def heappop_max(heap: list[_T], /) -> _T: ...
1716
def heappush_max(heap: list[_T], item: _T, /) -> None: ...
1817
def heappushpop_max(heap: list[_T], item: _T, /) -> _T: ...

stdlib/asyncio/queues.pyi

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import sys
2+
from _typeshed import SupportsRichComparisonT
23
from asyncio.events import AbstractEventLoop
34
from types import GenericAlias
45
from typing import Any, Generic, TypeVar
@@ -50,5 +51,5 @@ class Queue(Generic[_T], _LoopBoundMixin): # noqa: Y059
5051
if sys.version_info >= (3, 13):
5152
def shutdown(self, immediate: bool = False) -> None: ...
5253

53-
class PriorityQueue(Queue[_T]): ...
54+
class PriorityQueue(Queue[SupportsRichComparisonT]): ...
5455
class LifoQueue(Queue[_T]): ...

stdlib/queue.pyi

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import sys
22
from _queue import Empty as Empty, SimpleQueue as SimpleQueue
3+
from _typeshed import SupportsRichComparisonT
34
from threading import Condition, Lock
45
from types import GenericAlias
56
from typing import Any, Generic, TypeVar
@@ -47,8 +48,8 @@ class Queue(Generic[_T]):
4748
def task_done(self) -> None: ...
4849
def __class_getitem__(cls, item: Any, /) -> GenericAlias: ...
4950

50-
class PriorityQueue(Queue[_T]):
51-
queue: list[_T]
51+
class PriorityQueue(Queue[SupportsRichComparisonT]):
52+
queue: list[SupportsRichComparisonT]
5253

5354
class LifoQueue(Queue[_T]):
5455
queue: list[_T]

0 commit comments

Comments
 (0)