return, break or continue leaves a task group or nursery block, which still waits for every task first
What it finds
Leaving an async with task group does not stop its tasks: the jump waits until all of them finish, so an early return meant to give up does not, and a break out of a loop can hang. Cancelling the group's scope first makes the exit happen at once.
From the rule's source, jump_out_of_task_group.rs.
import asyncio async def main(items): async with asyncio.TaskGroup() as tg: for item in items: if item is None: returntx0 reports: leaving the task group still waits for all of its tasks if item == 0: break tg.create_task(work(item)) for item in items: async with asyncio.TaskGroup() as tg: tg.create_task(work(item)) continuetx0 reports: leaving the task group still waits Turn it on, off or suppress it
The rule runs from the recommended tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:jump-out-of-task-group" = "warning"To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:
# tx0: ignore[tx0/python:jump-out-of-task-group] reason="..."tx0 explain tx0/python:jump-out-of-task-group shows the same in the terminal. Found a false positive? Report it.