PY3.R1710

Inconsistent return statements

Either all return statements in a function should return an expression, or none of them should. 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).

Noncompliant Code:

Copy
def get_the_answer(value: str) -> str | None:
    if value:
        return value

Compliant Code:

Copy
def get_the_answer(value: str) -> str | None:
    if value:
        return value
    return None

The content on this page is adapted from the Pylint User Guide, Copyright ©2003-2022, Logilab, PyCQA and contributors. All rights reserved. https://pylint.pycqa.org/en/latest/index.html#, and is used under the Python Software Foundation License Version 2. Examples, recipes, and other code in the Pylint documentation are additionally licensed under the Zero Clause BSD License.