Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

R506 false positive when raise is used in elif #130

Open
nijel opened this issue Dec 15, 2022 · 1 comment
Open

R506 false positive when raise is used in elif #130

nijel opened this issue Dec 15, 2022 · 1 comment
Assignees

Comments

@nijel
Copy link

nijel commented Dec 15, 2022

  • Date you used flake8-return: 15th December 2022
  • flake8-return version used, if any: 1.2.0
  • Python version, if any: 3.9.2
  • Operating System: Linux

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
Copy link
Author

nijel commented Dec 15, 2022

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.

@afonasev afonasev self-assigned this Dec 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants