Skip to content

Commit 587d15a

Browse files
authored
bisect: fix type of x when key is present (#7097)
1 parent f86f096 commit 587d15a

File tree

1 file changed

+30
-8
lines changed

1 file changed

+30
-8
lines changed

stdlib/_bisect.pyi

Lines changed: 30 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,31 +1,53 @@
11
import sys
2-
from _typeshed import SupportsRichComparison
3-
from typing import Callable, MutableSequence, Sequence, TypeVar
2+
from _typeshed import SupportsRichComparisonT
3+
from typing import Callable, MutableSequence, Sequence, TypeVar, overload
44

55
_T = TypeVar("_T")
66

77
if sys.version_info >= (3, 10):
8+
@overload
9+
def bisect_left(a: Sequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: None = ...) -> int: ...
10+
@overload
811
def bisect_left(
9-
a: Sequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsRichComparison] | None = ...
12+
a: Sequence[_T],
13+
x: SupportsRichComparisonT,
14+
lo: int = ...,
15+
hi: int | None = ...,
16+
*,
17+
key: Callable[[_T], SupportsRichComparisonT] = ...,
1018
) -> int: ...
19+
@overload
20+
def bisect_right(a: Sequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: None = ...) -> int: ...
21+
@overload
1122
def bisect_right(
12-
a: Sequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: Callable[[_T], SupportsRichComparison] | None = ...
23+
a: Sequence[_T],
24+
x: SupportsRichComparisonT,
25+
lo: int = ...,
26+
hi: int | None = ...,
27+
*,
28+
key: Callable[[_T], SupportsRichComparisonT] = ...,
1329
) -> int: ...
30+
@overload
31+
def insort_left(a: MutableSequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: None = ...) -> None: ...
32+
@overload
1433
def insort_left(
1534
a: MutableSequence[_T],
16-
x: _T,
35+
x: SupportsRichComparisonT,
1736
lo: int = ...,
1837
hi: int | None = ...,
1938
*,
20-
key: Callable[[_T], SupportsRichComparison] | None = ...,
39+
key: Callable[[_T], SupportsRichComparisonT] = ...,
2140
) -> None: ...
41+
@overload
42+
def insort_right(a: MutableSequence[_T], x: _T, lo: int = ..., hi: int | None = ..., *, key: None = ...) -> None: ...
43+
@overload
2244
def insort_right(
2345
a: MutableSequence[_T],
24-
x: _T,
46+
x: SupportsRichComparisonT,
2547
lo: int = ...,
2648
hi: int | None = ...,
2749
*,
28-
key: Callable[[_T], SupportsRichComparison] | None = ...,
50+
key: Callable[[_T], SupportsRichComparisonT] = ...,
2951
) -> None: ...
3052

3153
else:

0 commit comments

Comments
 (0)