Add SupportsRichComparison type to _typeshed (#6583)

Use it to improve types of `max()` and other functions.

Also make some other tweaks to types related to comparison dunders.

Fixes #6575
This commit is contained in:
Alex Waygood
2021-12-14 14:12:23 +00:00
committed by GitHub
parent 968fd6d01d
commit 5670ca2f75
9 changed files with 73 additions and 69 deletions

View File

@@ -1,21 +1,31 @@
import sys
from _typeshed import SupportsLessThan
from _typeshed import SupportsRichComparison
from typing import Callable, MutableSequence, Sequence, TypeVar
_T = TypeVar("_T")
if sys.version_info >= (3, 10):
def bisect_left(
a: Sequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsLessThan] | None = ...
a: Sequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsRichComparison] | None = ...
) -> int: ...
def bisect_right(
a: Sequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsLessThan] | None = ...
a: Sequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsRichComparison] | None = ...
) -> int: ...
def insort_left(
a: MutableSequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsLessThan] | None = ...
a: MutableSequence[_T],
x: _T,
lo: int = ...,
hi: int | None = ...,
*,
key: Callable[[_T], SupportsRichComparison] | None = ...,
) -> None: ...
def insort_right(
a: MutableSequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsLessThan] | None = ...
a: MutableSequence[_T],
x: _T,
lo: int = ...,
hi: int | None = ...,
*,
key: Callable[[_T], SupportsRichComparison] | None = ...,
) -> None: ...
else: