Skip to content

yield-in-for-loop (UP028)#

Derived from the pyupgrade linter.

Fix is always available.

What it does#

Checks for for loops that can be replaced with yield from expressions.

Why is this bad?#

If a for loop only contains a yield statement, it can be replaced with a yield from expression, which is more concise and idiomatic.


for x in foo:
    yield x

Use instead:

yield from foo