A for loop only yields each item of an iterable, which yield from does directly
What it finds
for item in items: yield item hands on the items one by one; yield from items does the same and also passes on values sent into the generator and its close and throw. Async generators, which cannot use yield from, and loops with an else block are not affected. The fix writes yield from and is unsafe because of the forwarded calls.
From the rule's source, loop_yield_delegation.rs.
def walk(items): for item in items:tx0 reports: this loop only yields each item; yield from does that directly yield item for item in items: yield item * 2 for a, b in items: yield a async def stream(items): for item in items: yield item Turn it on, off or suppress it
The rule runs from the strict tier up. To turn it on in a lower tier, give it a level in tx0.toml:
[rules]
"tx0/python:loop-yield-delegation" = "note"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:loop-yield-delegation] reason="..."tx0 explain tx0/python:loop-yield-delegation shows the same in the terminal. Found a false positive? Report it.