8000 Fix itertools typing stubs (#140) · maxfischer2781/asyncstdlib@aaeb6d7 · GitHub
[go: up one dir, main page]

Skip to content

Commit aaeb6d7

Browse files
authored
Fix itertools typing stubs (#140)
* Fix itertools typing stubs
1 parent 04e0925 commit aaeb6d7

File tree

3 files changed

+82
-13
lines changed

3 files changed

+82
-13
lines changed

asyncstdlib/_typing.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def __lt__(self: LT, other: LT) -> bool:
6969

7070

7171
class SupportsAdd(Protocol):
72-
def __add__(self: ADD, other: ADD) -> ADD:
72+
def __add__(self: ADD, other: ADD, /) -> ADD:
7373
raise NotImplementedError
7474

7575

asyncstdlib/itertools.pyi

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -63,53 +63,51 @@ class chain(AsyncIterator[T]):
6363
async def aclose(self) -> None: ...
6464

6565
def compress(data: AnyIterable[T], selectors: AnyIterable[Any]) -> AsyncIterator[T]: ...
66-
async def dropwhile(
66+
def dropwhile(
6767
predicate: Callable[[T], Any], iterable: AnyIterable[T]
6868
) -> AsyncIterator[T]: ...
69-
async def filterfalse(
69+
def filterfalse(
7070
predicate: Callable[[T], Any] | None, iterable: AnyIterable[T]
7171
) -> AsyncIterator[T]: ...
7272
@overload
73-
async def islice(
74-
iterable: AnyIterable[T], start: int | None, /
75-
) -> AsyncIterator[T]: ...
73+
def islice(iterable: AnyIterable[T], start: int | None, /) -> AsyncIterator[T]: ...
7674
@overload
77-
async def islice(
75+
def islice(
7876
iterable: AnyIterable[T],
7977
start: int | None,
8078
stop: int | None,
8179
step: int | None = None,
8280
/,
8381
) -> AsyncIterator[T]: ...
8482
@overload
85-
async def starmap(
83+
def starmap(
8684
function: Callable[[T1], T] | Callable[[T1], Awaitable[T]],
8785
iterable: AnyIterable[tuple[T1]],
8886
) -> AsyncIterator[T]: ...
8987
@overload
90-
async def starmap(
88+
def starmap(
9189
function: Callable[[T1, T2], T] | Callable[[T1, T2], Awaitable[T]],
9290
iterable: AnyIterable[tuple[T1, T2]],
9391
) -> AsyncIterator[T]: ...
9492
@overload
95-
async def starmap(
93+
def starmap(
9694
function: Callable[[T1, T2, T3], T] | Callable[[T1, T2, T3], Awaitable[T]],
9795
iterable: AnyIterable[tuple[T1, T2, T3]],
9896
) -> AsyncIterator[T]: ...
9997
@overload
100-
async def starmap(
98+
def starmap(
10199
function: Callable[[T1, T2, T3, T4], T] | Callable[[T1, T2, T3, T4], Awaitable[T]],
102100
iterable: AnyIterable[tuple[T1, T2, T3, T4]],
103101
) -> AsyncIterator[T]: ...
104102
@overload
105-
async def starmap(
103+
def starmap(
106104
function: (
107105
Callable[[T1, T2, T3, T4, T5], T] | Callable[[T1, T2, T3, T4, T5], Awaitable[T]]
108106
),
109107
iterable: AnyIterable[tuple[T1, T2, T3, T4, T5]],
110108
) -> AsyncIterator[T]: ...
111109
@overload
112-
async def starmap(
110+
def starmap(
113111
function: Callable[..., T] | Callable[..., Awaitable[T]],
114112
iterable: AnyIterable[Iterable[Any]],
115113
) -> AsyncIterator[T]: ...

typetests/test_itertools.py

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
from typing import AsyncIterator
2+
from asyncstdlib import itertools
3+
from typing_extensions import assert_type
4+
5+
6+
async def test_cycle() -> None:
7+
async for x in itertools.cycle([1]):
8+
assert_type(x, int)
9+
10+
11+
async def test_accumulate() -> None:
12+
async for x in itertools.accumulate([1]):
13+
assert_type(x, int)
14+
15+
16+
async def test_batched() -> None:
17+
async for x in itertools.batched([1], 1):
18+
assert_type(x, "tuple[int]")
19+
20+
21+
async def test_chain() -> None:
22+
async for x in itertools.chain([1]):
23+
assert_type(x, int)
24+
25+
26+
async def test_compress() -> None:
27+
async for x in itertools.compress([1], [1]):
28+
assert_type(x, int)
29+
30+
31+
async def test_dropwhile() -> None:
32+
async for x in itertools.dropwhile(lambda x: True, [1]):
33+
assert_type(x, int)
34+
35+
36+
async def test_filterfalse() -> None:
37+
async for x in itertools.filterfalse(lambda x: True, [1]):
38+
assert_type(x, int)
39+
40+
41+
async def test_starmap() -> None:
42+
def f(x: str) -> int:
43+
return int(x)
44+
45+
async for x in itertools.starmap(f, [("1",)]):
46+
assert_type(x, int)
47+
48+
49+
async def test_takewhile() -> None:
50+
async for x in itertools.takewhile(lambda x: True, [1]):
51+
assert_type(x, int)
52+
53+
54+
async def test_tee() -> None:
55+
async for x in itertools.tee([1])[0]:
56+
assert_type(x, int)
57+
58+
59+
async def test_pairwise() -> None:
60+
async for x in itertools.pairwise([1]):
61+
assert_type(x, "tuple[int, int]")
62+
63+
64+
async def test_zip_longest() -> None:
65+
async for x in itertools.zip_longest([1]):
66+
assert_type(x, "tuple[int]")
67+
68+
69+
async def test_groupby() -> None:
70+
async for x in itertools.groupby([1]):
71+
assert_type(x, "tuple[int, AsyncIterator[int]]")

0 commit comments

Comments
 (0)
0