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

False positive on R504 #3

Closed
nijel opened this issue May 16, 2019 · 3 comments
Closed

False positive on R504 #3

nijel opened this issue May 16, 2019 · 3 comments
Assignees

Comments

@nijel
Copy link

nijel commented May 16, 2019

  • 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
Copy link
Owner

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

@afonasev afonasev self-assigned this May 22, 2019
@nijel
Copy link
Author

nijel commented May 22, 2019

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

it looks like a bug, I'll try to fix it soon, thx

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