python / mypy

Optional static typing for Python
https://www.mypy-lang.org/
Other
18.19k stars 2.78k forks source link

Unused awaitable with TaskGroup #15036

Open Dreamsorcerer opened 1 year ago

Dreamsorcerer commented 1 year ago
import asyncio

async def main() -> None:
    async with asyncio.TaskGroup() as tg:
        tg.create_task(asyncio.sleep(1))

With unused-awaitable enabled, this code generates an unused awaitable error. TaskGroup is expected to wait on any created tasks, so there is no need to await on them.

Perhaps TaskGroup can be special-cased to ignore this error, or maybe special-case Task so the rule only applies when it is returned from asyncio.create_task()?

alexpovel commented 1 year ago

Just upgraded to mypy 1.5 and Python 3.11.4, and can reproduce this behaviour.

hauntsaninja commented 1 year ago

PR welcome!