Skip to content
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.

Commit 9a58a26

Browse files
committedMay 17, 2024
Update bundled typeshed
1 parent c55a3b4 commit 9a58a26

File tree

230 files changed

+6758
-4000
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

230 files changed

+6758
-4000
lines changed
 
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from __future__ import annotations
2+
3+
from asyncio import iscoroutinefunction
4+
from collections.abc import Awaitable, Callable, Coroutine
5+
from typing import Any
6+
from typing_extensions import assert_type
7+
8+
9+
def test_iscoroutinefunction(
10+
x: Callable[[str, int], Coroutine[str, int, bytes]],
11+
y: Callable[[str, int], Awaitable[bytes]],
12+
z: Callable[[str, int], str | Awaitable[bytes]],
13+
xx: object,
14+
) -> None:
15+
if iscoroutinefunction(x):
16+
assert_type(x, Callable[[str, int], Coroutine[str, int, bytes]])
17+
18+
if iscoroutinefunction(y):
19+
assert_type(y, Callable[[str, int], Coroutine[Any, Any, bytes]])
20+
21+
if iscoroutinefunction(z):
22+
assert_type(z, Callable[[str, int], Coroutine[Any, Any, Any]])
23+
24+
if iscoroutinefunction(xx):
25+
assert_type(xx, Callable[..., Coroutine[Any, Any, Any]])
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
from __future__ import annotations
2+
3+
import asyncio
4+
from typing import Awaitable, List, Tuple, Union
5+
from typing_extensions import assert_type
6+
7+
8+
async def coro1() -> int:
9+
return 42
10+
11+
12+
async def coro2() -> str:
13+
return "spam"
14+
15+
16+
async def test_gather(awaitable1: Awaitable[int], awaitable2: Awaitable[str]) -> None:
17+
a = await asyncio.gather(awaitable1)
18+
assert_type(a, Tuple[int])
19+
20+
b = await asyncio.gather(awaitable1, awaitable2, return_exceptions=True)
21+
assert_type(b, Tuple[Union[int, BaseException], Union[str, BaseException]])
22+
23+
c = await asyncio.gather(awaitable1, awaitable2, awaitable1, awaitable1, awaitable1, awaitable1)
24+
assert_type(c, Tuple[int, str, int, int, int, int])
25+
26+
d = await asyncio.gather(awaitable1, awaitable1, awaitable1, awaitable1, awaitable1, awaitable1, awaitable1)
27+
assert_type(d, List[int])
28+
29+
awaitables_list: list[Awaitable[int]] = [awaitable1]
30+
e = await asyncio.gather(*awaitables_list)
31+
assert_type(e, List[int])
32+
33+
# this case isn't reliable between typecheckers, no one would ever call it with no args anyway
34+
# f = await asyncio.gather()
35+
# assert_type(f, list[Any])
36+
37+
38+
asyncio.run(test_gather(coro1(), coro2()))

0 commit comments

Comments
 (0)
Please sign in to comment.