Skip to content

Instantly share code, notes, and snippets.

@amyreese
Created October 27, 2019 00:03
Show Gist options
  • Save amyreese/5653cf9c51e71cb924bf0b9763e44727 to your computer and use it in GitHub Desktop.
Save amyreese/5653cf9c51e71cb924bf0b9763e44727 to your computer and use it in GitHub Desktop.
diff --git a/aioitertools/asyncio.py b/aioitertools/asyncio.py
index a98b961..0038f02 100644
--- a/aioitertools/asyncio.py
+++ b/aioitertools/asyncio.py
@@ -9,7 +9,7 @@ Provisional library. Must be imported as `aioitertools.asyncio`.
import asyncio
import time
-from typing import Awaitable, Iterable, Optional, Set
+from typing import Awaitable, Iterable, Optional, Set, Tuple, cast
from .types import AsyncIterator, T
@@ -47,8 +47,16 @@ async def as_completed(
if remaining <= 0:
raise asyncio.TimeoutError()
- done, pending = await asyncio.wait( # type: ignore # bad annotation upstream
- pending, loop=loop, timeout=remaining, return_when=asyncio.FIRST_COMPLETED
+ # casting results to Set[Awaitable[T]] because asyncio.Future is an Awaitable
+ # but mypy doesn't like assigning Set[asynico.Future] to Set[Awaitable]
+ done, pending = cast(
+ Tuple[Set[Awaitable[T]], Set[Awaitable[T]]],
+ await asyncio.wait(
+ pending,
+ loop=loop,
+ timeout=remaining,
+ return_when=asyncio.FIRST_COMPLETED,
+ ),
)
for item in done:
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment