Skip to content

yield-outside-function

Pythoncorrectnessno fixdefault: warnpython/ruff

Reports a yield, yield from or await outside a function.

Python rejects the file with a SyntaxError ('yield' outside function, 'await' outside function), so no code in it runs.

To fix, put the code in a function (an async def for await).

Reported
...
...
yield 1
await x
def f():
class A:
yield 1
try:
pass
...
python:
lint:
rules:
yield-outside-function: warn # off, warn (default), error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line yield-outside-function in a comment of the file’s language.

The same check in other tools; Sudsy reports what each upstream rule reports.

Tool Rule Match
ruff F704 full