R1710 inconsistent-return-statements

Message

'Either all return statements in a function should return an expression, or none of them should.'

Description

According to PEP8, if any return statement returns an expression, any return statements where no value is returned should explicitly state this as return None, and an explicit return statement should be present at the end of the function (if reachable)

Examples

In the following example we implicitly return None if the condition of the if-statement was not met.

def example(arg):
    if arg > 1:
        return 1
1:0: R1710: Either all return statements in a function should return an expression, or none of them should.

This can be fixed by adding an explicit return statement.

def example(arg):
    if arg > 1:
        return 1
    return None
No issues found.

Running Pylint locally? In your CI?

There is a better way! Run PyCodeQual & get Pylint findings with history, diffs and statistics.

Click here to find out more.