Closed
Description
The following code fails to typecheck with mypy but works just fine at runtime.
import asyncio
from typing import AsyncGenerator
async def func() -> AsyncGenerator[int, None]:
yield 1
async def main() -> None:
a = func()
print(await asyncio.create_task(a.asend(None)))
asyncio.run(main())
Error:
❯ mypy main.py
main.py:11: error: Argument 1 to "create_task" has incompatible type "Awaitable[int]"; expected "Union[Generator[Any, None, <nothing>], Coroutine[Any, Any, <nothing>]]" [arg-type]
main.py:11: error: Argument 1 to "create_task" has incompatible type "Awaitable[int]"; expected "Union[Generator[Any, None, object], Coroutine[Any, Any, object]]" [arg-type]
Found 2 errors in 1 file (checked 1 source file)
mypy version: mypy 1.0.0 (compiled: yes)