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

R505+R508 false positive #137

Open
luisrayas3 opened this issue Jan 24, 2024 · 0 comments
Open

R505+R508 false positive #137

luisrayas3 opened this issue Jan 24, 2024 · 0 comments

Comments

@luisrayas3
Copy link

  • Date you used flake8-return: 2024-01-24
  • flake8-return version used, if any: 1.2.0
  • Python version, if any: 3.7
  • Operating System: Linux (Ubuntu)

Description

R505 & R508 produce false-positives when an earlier branch does not return/break.

What I did

$ cat f.py
def f():
    if True:
        print("1")
    elif False:
        return False
    elif True:
        print("2")
    return True

if __name__ == "__main__":
    f()
$ flake3 f.py
/tmp/f.py:6:10: R505 unnecessary elif after return statement.
    elif False:
         ^
...
1     R505 unnecessary elif after return statement.
...

Same thing if the if-chain is contained in a loop and the return is a break instead.

Note that not using an elif after causes a behavior change: print("2") will be called when it shouldn't be. These warnings should only trigger if every case in the if/elif/else chain returns, breaks, or raises.

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

1 participant