10000 Add better types for asyncio.gather by Gobot1234 · Pull Request #9678 · python/typeshed · GitHub
[go: up one dir, main page]

Skip to content

Add better types for asyncio.gather #9678

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 14 commits into from
Oct 4, 2023
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Does removing the default help?
  • Loading branch information
Gobot1234 committed Oct 2, 2023
commit 36097ad1fcb4799ccfb49f300fa677218b885af1
4 changes: 2 additions & 2 deletions stdlib/asyncio/tasks.pyi
Original file line number Diff line number Diff line change
Expand Up @@ -174,7 +174,7 @@ if sys.version_info >= (3, 10):
]
]: ...
@overload
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: bool = False) -> Future[list[_T | BaseException]]: ... # type: ignore[misc]
def gather(*coros_or_futures: _FutureLike[_T], return_exceptions: bool) -> Future[list[_T | BaseException]]: ... # type: ignore[misc]

else:
@overload
Expand Down Expand Up @@ -285,7 +285,7 @@ else:
]: ...
@overload
def gather( # type: ignore[misc]
*coros_or_futures: _FutureLike[_T], loop: AbstractEventLoop | None = None, return_exceptions: bool = False
*coros_or_futures: _FutureLike[_T], loop: AbstractEventLoop | None = None, return_exceptions: bool
) -> Future[list[_T | BaseException]]: ...

def run_coroutine_threadsafe(coro: _FutureLike[_T], loop: AbstractEventLoop) -> concurrent.futures.Future[_T]: ...
Expand Down
5 changes: 3 additions & 2 deletions test_cases/stdlib/asyncio/check_gather.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,9 @@ async def test_gather(awaitable1: Awaitable[int], awaitable2: Awaitable[str]) ->
d = await asyncio.gather(*awaitables_list)
assert_type(d, List[int])

e = await asyncio.gather() # type: ignore[reportUnknownVariableType] # type is list[Unknown]
assert_type(e, list[Any])
# this case isn't reliable between typecheckers, no one would ever call it with no args anyway
# e = await asyncio.gather()
# assert_type(e, list[Any])


asyncio.run(test_gather(coro1(), coro2()))
0