mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-08 04:54:47 +08:00
_typeshed: add SupportsLessThan, SupportsLessThanT (#4711)
And use it everywhere. Note there seemed to be a discrepancy between heapq in Python 2 and 3, so I changed that. It should probably be more widely used within heapq, but leaving that out of scope for this PR. Co-authored-by: hauntsaninja <>
This commit is contained in:
@@ -8,6 +8,8 @@ from _typeshed import (
|
||||
OpenTextMode,
|
||||
ReadableBuffer,
|
||||
SupportsKeysAndGetItem,
|
||||
SupportsLessThan,
|
||||
SupportsLessThanT,
|
||||
SupportsWrite,
|
||||
)
|
||||
from abc import ABCMeta
|
||||
@@ -67,9 +69,6 @@ class _SupportsIndex(Protocol):
|
||||
class _SupportsTrunc(Protocol):
|
||||
def __trunc__(self) -> int: ...
|
||||
|
||||
class _SupportsLessThan(Protocol):
|
||||
def __lt__(self, __other: Any) -> bool: ...
|
||||
|
||||
_T = TypeVar("_T")
|
||||
_T_co = TypeVar("_T_co", covariant=True)
|
||||
_KT = TypeVar("_KT")
|
||||
@@ -81,7 +80,6 @@ _T3 = TypeVar("_T3")
|
||||
_T4 = TypeVar("_T4")
|
||||
_T5 = TypeVar("_T5")
|
||||
_TT = TypeVar("_TT", bound="type")
|
||||
_SupportsLessThanT = TypeVar("_SupportsLessThanT", bound=_SupportsLessThan)
|
||||
_TBE = TypeVar("_TBE", bound="BaseException")
|
||||
|
||||
class object:
|
||||
@@ -714,9 +712,9 @@ class list(MutableSequence[_T], Generic[_T]):
|
||||
def remove(self, __value: _T) -> None: ...
|
||||
def reverse(self) -> None: ...
|
||||
@overload
|
||||
def sort(self: List[_SupportsLessThanT], *, key: None = ..., reverse: bool = ...) -> None: ...
|
||||
def sort(self: List[SupportsLessThanT], *, key: None = ..., reverse: bool = ...) -> None: ...
|
||||
@overload
|
||||
def sort(self, *, key: Callable[[_T], _SupportsLessThan], reverse: bool = ...) -> None: ...
|
||||
def sort(self, *, key: Callable[[_T], SupportsLessThan], reverse: bool = ...) -> None: ...
|
||||
def __len__(self) -> int: ...
|
||||
def __iter__(self) -> Iterator[_T]: ...
|
||||
def __str__(self) -> str: ...
|
||||
@@ -1024,32 +1022,32 @@ def map(
|
||||
) -> Iterator[_S]: ...
|
||||
@overload
|
||||
def max(
|
||||
__arg1: _SupportsLessThanT, __arg2: _SupportsLessThanT, *_args: _SupportsLessThanT, key: None = ...
|
||||
) -> _SupportsLessThanT: ...
|
||||
__arg1: SupportsLessThanT, __arg2: SupportsLessThanT, *_args: SupportsLessThanT, key: None = ...
|
||||
) -> SupportsLessThanT: ...
|
||||
@overload
|
||||
def max(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], _SupportsLessThanT]) -> _T: ...
|
||||
def max(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], SupportsLessThanT]) -> _T: ...
|
||||
@overload
|
||||
def max(__iterable: Iterable[_SupportsLessThanT], *, key: None = ...) -> _SupportsLessThanT: ...
|
||||
def max(__iterable: Iterable[SupportsLessThanT], *, key: None = ...) -> SupportsLessThanT: ...
|
||||
@overload
|
||||
def max(__iterable: Iterable[_T], *, key: Callable[[_T], _SupportsLessThanT]) -> _T: ...
|
||||
def max(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsLessThanT]) -> _T: ...
|
||||
@overload
|
||||
def max(__iterable: Iterable[_SupportsLessThanT], *, key: None = ..., default: _T) -> Union[_SupportsLessThanT, _T]: ...
|
||||
def max(__iterable: Iterable[SupportsLessThanT], *, key: None = ..., default: _T) -> Union[SupportsLessThanT, _T]: ...
|
||||
@overload
|
||||
def max(__iterable: Iterable[_T1], *, key: Callable[[_T1], _SupportsLessThanT], default: _T2) -> Union[_T1, _T2]: ...
|
||||
def max(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsLessThanT], default: _T2) -> Union[_T1, _T2]: ...
|
||||
@overload
|
||||
def min(
|
||||
__arg1: _SupportsLessThanT, __arg2: _SupportsLessThanT, *_args: _SupportsLessThanT, key: None = ...
|
||||
) -> _SupportsLessThanT: ...
|
||||
__arg1: SupportsLessThanT, __arg2: SupportsLessThanT, *_args: SupportsLessThanT, key: None = ...
|
||||
) -> SupportsLessThanT: ...
|
||||
@overload
|
||||
def min(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], _SupportsLessThanT]) -> _T: ...
|
||||
def min(__arg1: _T, __arg2: _T, *_args: _T, key: Callable[[_T], SupportsLessThanT]) -> _T: ...
|
||||
@overload
|
||||
def min(__iterable: Iterable[_SupportsLessThanT], *, key: None = ...) -> _SupportsLessThanT: ...
|
||||
def min(__iterable: Iterable[SupportsLessThanT], *, key: None = ...) -> SupportsLessThanT: ...
|
||||
@overload
|
||||
def min(__iterable: Iterable[_T], *, key: Callable[[_T], _SupportsLessThanT]) -> _T: ...
|
||||
def min(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsLessThanT]) -> _T: ...
|
||||
@overload
|
||||
def min(__iterable: Iterable[_SupportsLessThanT], *, key: None = ..., default: _T) -> Union[_SupportsLessThanT, _T]: ...
|
||||
def min(__iterable: Iterable[SupportsLessThanT], *, key: None = ..., default: _T) -> Union[SupportsLessThanT, _T]: ...
|
||||
@overload
|
||||
def min(__iterable: Iterable[_T1], *, key: Callable[[_T1], _SupportsLessThanT], default: _T2) -> Union[_T1, _T2]: ...
|
||||
def min(__iterable: Iterable[_T1], *, key: Callable[[_T1], SupportsLessThanT], default: _T2) -> Union[_T1, _T2]: ...
|
||||
@overload
|
||||
def next(__i: Iterator[_T]) -> _T: ...
|
||||
@overload
|
||||
@@ -1209,9 +1207,9 @@ def round(number: SupportsRound[_T], ndigits: None) -> int: ...
|
||||
def round(number: SupportsRound[_T], ndigits: int) -> _T: ...
|
||||
def setattr(__obj: Any, __name: str, __value: Any) -> None: ...
|
||||
@overload
|
||||
def sorted(__iterable: Iterable[_SupportsLessThanT], *, key: None = ..., reverse: bool = ...) -> List[_SupportsLessThanT]: ...
|
||||
def sorted(__iterable: Iterable[SupportsLessThanT], *, key: None = ..., reverse: bool = ...) -> List[SupportsLessThanT]: ...
|
||||
@overload
|
||||
def sorted(__iterable: Iterable[_T], *, key: Callable[[_T], _SupportsLessThan], reverse: bool = ...) -> List[_T]: ...
|
||||
def sorted(__iterable: Iterable[_T], *, key: Callable[[_T], SupportsLessThan], reverse: bool = ...) -> List[_T]: ...
|
||||
|
||||
if sys.version_info >= (3, 8):
|
||||
@overload
|
||||
|
||||
Reference in New Issue
Block a user