Files
typeshed/stdlib/2/heapq.pyi
Yannack 40215d1fa3 Fix the definition of nsmallest() in stdlib/2 and 2and3/heapq.pyi (#3114)
Missing support of the optional "key" kwarg in nsmallest.
Also fixed nlargest syntax for 2and3 which was also missing.
Use a protocol for heapq.py
2019-07-18 21:38:28 +02:00

21 lines
824 B
Python

from typing import TypeVar, List, Iterable, Any, Callable, Optional, Protocol
_T = TypeVar('_T')
class _Sortable(Protocol):
def __lt__(self: _T, other: _T) -> bool: ...
def cmp_lt(x, y) -> bool: ...
def heappush(heap: List[_T], item: _T) -> None: ...
def heappop(heap: List[_T]) -> _T:
raise IndexError() # if heap is empty
def heappushpop(heap: List[_T], item: _T) -> _T: ...
def heapify(x: List[_T]) -> None: ...
def heapreplace(heap: List[_T], item: _T) -> _T:
raise IndexError() # if heap is empty
def merge(*iterables: Iterable[_T]) -> Iterable[_T]: ...
def nlargest(n: int, iterable: Iterable[_T],
key: Optional[Callable[[_T], _Sortable]] = ...) -> List[_T]: ...
def nsmallest(n: int, iterable: Iterable[_T],
key: Optional[Callable[[_T], _Sortable]] = ...) -> List[_T]: ...