Skip to content

asyncio.create_task doesn't accept async_generator_asend objects #10185

Description

@kumaraditya303

The following code fails to typecheck with mypy but works just fine at runtime.

importasynciofromtypingimportAsyncGeneratorasyncdeffunc() ->AsyncGenerator[int, None]:
yield1asyncdefmain() ->None:
a=func()
print(awaitasyncio.create_task(a.asend(None)))
asyncio.run(main())

Error:

mypy main.pymain.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)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions