PY3.R1720

No else raise

Used in order to highlight an unnecessary block of code following an if containing a raise statement. As such, it will warn when it encounters an else following a chain of if s, all of them containing a raise statement.

Noncompliant Code:

Copy
def integer_sum(a: int, b: int) -> int:
    if not (isinstance(a, int) and isinstance(b, int)):
        raise ValueError('Function supports only integer parameters.')
    else:
        return a + b

Compliant Code:

Copy
def integer_sum(a: int, b: int) -> int:
    if not (isinstance(a, int) and isinstance(b, int)):
        raise ValueError('Function supports only integer parameters.')
    return a + b

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.