False positive on R504
nijel opened this issue · 3 comments
nijel commented
- Date you used flake8-return: 2019-05-16
- flake8-return version used, if any: 1.0.0
- Python version, if any: 3.7.1
- Operating System: Debian
Description
The R504 doesn't detect that the variable is conditionally modified prior to return.
What I Did
$ flake8 test.py
test.py:5:12: R504 you shouldn`t assign value to variable if it will be use only as return value
$ cat test.py
def foo(bar):
value = []
if bar:
value = value[:1]
return value
afonasev commented
Hello. Linter offers to immediately make a return, instead of changing the value of a variable that will no longer be used or changed. i.e.
def foo(bar):
value = []
if bar:
return value[:1]
return value
nijel commented
Okay, it might be reasonable in some situations with if, but let's take another example with for:
def clean_fullname(val):
"""Remove special chars from user full name."""
val = val.strip()
for i in range(0x20):
val = val.replace(chr(i), '')
return val
afonasev commented
it looks like a bug, I'll try to fix it soon, thx