afonasev / flake8-return

Flake8 plugin for return expressions checking.
MIT License
62 stars 69 forks source link

R506 false positive when raise is used in elif #130

Open nijel opened 1 year ago

nijel commented 1 year ago

Description

Linting following code:

def test_2(bar):
    if bar == 3:
        baz = 1
    elif bar == 4:
        raise Exception()
    else:
        baz = 2
    return baz

What I Did

$ flake8 test.py 
test.py:4:5: R506 unnecessary else after raise statement.

The else is necessary as there is additional if before which has side effects and removing else would overwrite that. The code is simplified from real-world code.

nijel commented 1 year ago

The very same issue is with return and R505:

def test_2(bar):
    if bar == 3:
        baz = 1
    elif bar == 4:
        return 3
    else:
        baz = 2
    return baz
$ flake8 test.py 
test.py:4:5: R505 unnecessary else after return statement.