Skip to content

Latest commit

 

History

History
28 lines (21 loc) · 608 Bytes

no-else-raise.md

File metadata and controls

28 lines (21 loc) · 608 Bytes

Pattern: Unnecessary else after raise

Issue: -

Description

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 ifs, all of them containing a raise statement.

Example of incorrect code:

def test(x, y, z):
    if x:  # [no-else-raise]
        a = 1
        raise Exception(y)
    else:
        b = 2
        raise Exception(z)

Example of correct code:

def test(x, y, z):
    if x:
        raise Exception(y)
    raise Exception(z)