flake8-return
flake8-return copied to clipboard
Invalid error reported for R505 simple if - elif pattern
- Date you used flake8-return: 2022-10-31
- flake8-return version used, if any: 1.2.0
- Python version, if any: Python 3.10.6
- Operating System: macOS
Description
Invalid error reported for R505 simple if - elif pattern
def get_name(name):
if name == 'foo':
return 'foo'
elif name == 'bar':
return 'bar'
return 'baz'
What I Did
a.py:2:5: R505 unnecessary elif after return statement.
I think this pattern should be passed.
The R505 rule was ported from pylint as suggested in #14.
As plyint also throws an error in this case, I do not believe this is a false positive.
src/a.py:2:4: R1705: Unnecessary "elif" after "return", remove the leading "el" from "elif" (no-else-return)
I see the same behavior within classes using the 1.2.0 version.
def foo(name):
[...]
return True
def bar(name):
if "foo" == "bar": <----
return 'baz'
The if statement in bar
gets flagged with an R505
because of the return
in foo.
I encountered a similar issue e.g:
if op == Op.EQUAL:
return left_value == right_value
elif op == Op.NOT_EQUAL:
return left_value != right_value
I deactivated R505
because of too many false positives.