Skip to content

return-outside-function

Pythoncorrectnessno fixdefault: warnpython/ruff

Reports a return that is not inside a function.

Python rejects the file with SyntaxError: 'return' outside function.

To fix, remove it, or move the code into a function.

Reported
return 1
def f():
...
...
return 2
python:
lint:
rules:
return-outside-function: warn # off, warn (default), error

Enabled by the presets: python/ruff.

Suppress one line with sudsy-disable-next-line return-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 F706 full