mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
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
This commit is contained in:
committed by
Sebastian Rittau
parent
09d1055cd3
commit
40215d1fa3
@@ -1,7 +1,10 @@
|
||||
from typing import TypeVar, List, Iterable, Any, Callable, Optional
|
||||
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:
|
||||
@@ -12,5 +15,6 @@ 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], Any]] = ...) -> List[_T]: ...
|
||||
def nsmallest(n: int, iterable: Iterable[_T]) -> List[_T]: ...
|
||||
key: Optional[Callable[[_T], _Sortable]] = ...) -> List[_T]: ...
|
||||
def nsmallest(n: int, iterable: Iterable[_T],
|
||||
key: Optional[Callable[[_T], _Sortable]] = ...) -> List[_T]: ...
|
||||
|
||||
Reference in New Issue
Block a user