forked from python/typeshed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
The stubs were requiring SupportsRichComparisonT, but bisect only uses __lt__. Be more specific as to which comparison is actually required, which depends on the function. This allows using bisect with types that only implement __lt__. Closes python#13347.
- Loading branch information
Showing
1 changed file
with
56 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,84 +1,121 @@ | ||
import sys | ||
from _typeshed import SupportsLenAndGetItem, SupportsRichComparisonT | ||
from _typeshed import SupportsDunderLT, SupportsLenAndGetItem | ||
from collections.abc import Callable, MutableSequence | ||
from typing import TypeVar, overload | ||
|
||
_T = TypeVar("_T") | ||
_U = TypeVar("_U") | ||
|
||
if sys.version_info >= (3, 10): | ||
@overload | ||
def bisect_left( | ||
a: SupportsLenAndGetItem[SupportsRichComparisonT], | ||
x: SupportsRichComparisonT, | ||
# Valid comparison: a[i] < x | ||
a: SupportsLenAndGetItem[SupportsDunderLT[_T]], | ||
x: _T, | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: None = None, | ||
) -> int: ... | ||
@overload | ||
def bisect_left( | ||
# Valid comparison: key(a[i]) < x | ||
a: SupportsLenAndGetItem[_T], | ||
x: SupportsRichComparisonT, | ||
x: _U, | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: Callable[[_T], SupportsRichComparisonT], | ||
key: Callable[[_T], SupportsDunderLT[_U]], | ||
) -> int: ... | ||
@overload | ||
def bisect_right( | ||
a: SupportsLenAndGetItem[SupportsRichComparisonT], | ||
x: SupportsRichComparisonT, | ||
# Valid comparison: x < a[i] | ||
a: SupportsLenAndGetItem[_T], | ||
x: SupportsDunderLT[_T], | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: None = None, | ||
) -> int: ... | ||
@overload | ||
def bisect_right( | ||
# Valid comparison: x < key(a[i]) | ||
a: SupportsLenAndGetItem[_T], | ||
x: SupportsRichComparisonT, | ||
x: SupportsDunderLT[_U], | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: Callable[[_T], SupportsRichComparisonT], | ||
key: Callable[[_T], _U], | ||
) -> int: ... | ||
@overload | ||
def insort_left( | ||
a: MutableSequence[SupportsRichComparisonT], | ||
x: SupportsRichComparisonT, | ||
# Valid comparison: a[i] < x | ||
a: MutableSequence[SupportsDunderLT[_T]], | ||
x: _T, | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: None = None, | ||
) -> None: ... | ||
@overload | ||
def insort_left( | ||
a: MutableSequence[_T], x: _T, lo: int = 0, hi: int | None = None, *, key: Callable[[_T], SupportsRichComparisonT] | ||
# Valid comparison: key(a[i]) < x | ||
a: MutableSequence[_T], | ||
x: _T, | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: Callable[[_T], SupportsDunderLT[_T]], | ||
) -> None: ... | ||
@overload | ||
def insort_right( | ||
a: MutableSequence[SupportsRichComparisonT], | ||
x: SupportsRichComparisonT, | ||
# Valid comparison: x < a[i] | ||
a: MutableSequence[_T], | ||
x: SupportsDunderLT[_T], | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: None = None, | ||
) -> None: ... | ||
@overload | ||
def insort_right( | ||
a: MutableSequence[_T], x: _T, lo: int = 0, hi: int | None = None, *, key: Callable[[_T], SupportsRichComparisonT] | ||
# Valid comparison: x < key(a[i]) | ||
a: MutableSequence[_T], | ||
x: SupportsDunderLT[_U], | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: Callable[[_T], _U], | ||
) -> None: ... | ||
|
||
else: | ||
def bisect_left( | ||
a: SupportsLenAndGetItem[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None | ||
# Valid comparison: a[i] < x | ||
a: SupportsLenAndGetItem[SupportsDunderLT[_T]], | ||
x: _T, | ||
lo: int = 0, | ||
hi: int | None = None, | ||
) -> int: ... | ||
def bisect_right( | ||
a: SupportsLenAndGetItem[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None | ||
# Valid comparison: x < a[i] | ||
a: SupportsLenAndGetItem[_T], | ||
x: SupportsDunderLT[_T], | ||
lo: int = 0, | ||
hi: int | None = None, | ||
) -> int: ... | ||
def insort_left( | ||
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None | ||
# Valid comparison: a[i] < x | ||
a: MutableSequence[SupportsDunderLT[_T]], | ||
x: _T, | ||
lo: int = 0, | ||
hi: int | None = None, | ||
) -> None: ... | ||
def insort_right( | ||
a: MutableSequence[SupportsRichComparisonT], x: SupportsRichComparisonT, lo: int = 0, hi: int | None = None | ||
# Valid comparison: x < a[i] | ||
a: MutableSequence[_T], | ||
x: SupportsDunderLT[_T], | ||
lo: int = 0, | ||
hi: int | None = None, | ||
*, | ||
key: None = None, | ||
) -> None: ... |