Skip to content

useless-return (PLR1711)

Added in v0.0.257 · Related issues · View source

Derived from the Pylint linter.

Fix is always available.

What it does

Checks for functions that end with an unnecessary return or return None, and contain no other return statements.

Why is this bad?

Python implicitly assumes a None return at the end of a function, making it unnecessary to explicitly write return None.

Example

def f():
    print(5)
    return None

Use instead:

def f():
    print(5)

Fix safety

A trailing comment on the same line as the return statement is preserved. The fix is marked as unsafe if it would delete any other comments, such as comments inside a parenthesized return value.