Skip to content

explicit-return-none

Pythonstyleno fixdefault: offpython/ruff

Reports return None in a function whose other returns, if any, return nothing or None. A function that is a generator, one whose only statement is return None, a property and a function annotated with anything but None are left alone.

A function without a value returns None anyway, so the word adds nothing. The explicit form is needed where another return has a value, to tell the reader that None is meant, and that case is not reported.

To fix, write return, or remove it at the end of the function.

Reported
...
...
if x:
return None
print(x)
x = 1
...
python:
lint:
rules:
explicit-return-none: warn # off (default), warn, error

Enabled by the presets: python/ruff.

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