mirror of
https://github.com/davidhalter/typeshed.git
synced 2025-12-30 16:14:24 +08:00
Add better types for asyncio.gather (#9678)
This commit is contained in:
committed by
GitHub
parent
c30c85dfcb
commit
25eb99cbec
@@ -1,7 +1,7 @@
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
from typing import Any, Awaitable, List, Tuple, Union
|
||||
from typing import Awaitable, List, Tuple, Union
|
||||
from typing_extensions import assert_type
|
||||
|
||||
|
||||
@@ -21,14 +21,18 @@ async def test_gather(awaitable1: Awaitable[int], awaitable2: Awaitable[str]) ->
|
||||
assert_type(b, Tuple[Union[int, BaseException], Union[str, BaseException]])
|
||||
|
||||
c = await asyncio.gather(awaitable1, awaitable2, awaitable1, awaitable1, awaitable1, awaitable1)
|
||||
assert_type(c, List[Any])
|
||||
assert_type(c, Tuple[int, str, int, int, int, int])
|
||||
|
||||
d = await asyncio.gather(awaitable1, awaitable1, awaitable1, awaitable1, awaitable1, awaitable1, awaitable1)
|
||||
assert_type(d, List[int])
|
||||
|
||||
awaitables_list: list[Awaitable[int]] = [awaitable1]
|
||||
d = await asyncio.gather(*awaitables_list)
|
||||
assert_type(d, List[Any])
|
||||
e = await asyncio.gather(*awaitables_list)
|
||||
assert_type(e, List[int])
|
||||
|
||||
e = await asyncio.gather()
|
||||
assert_type(e, List[Any])
|
||||
# this case isn't reliable between typecheckers, no one would ever call it with no args anyway
|
||||
# f = await asyncio.gather()
|
||||
# assert_type(f, list[Any])
|
||||
|
||||
|
||||
asyncio.run(test_gather(coro1(), coro2()))
|
||||
|
||||
Reference in New Issue
Block a user