afonasev / flake8-return

Flake8 plugin for return expressions checking.
MIT License
62 stars 69 forks source link

Bad `R504` for assignment in a loop body #66

Closed Zac-HD closed 2 years ago

Zac-HD commented 3 years ago

Running flake8-return with Python 3.7, I get an R504 error for the following code:

def close(self):
    any_failed = False
    for task in self.tasks:
        try:
            task()
        except BaseException:
            any_failed = True
            report(traceback.format_exc())
    return any_failed  # R504 you shouldn't assign value to variable if it will be use only as return value

While any_failed is not used in any other expressions before being returned, it's still important to run all cleanup tasks instead of returning immediately after the first error. Perhaps R504 should be disabled when the assignment is in a loop and the return statement is not?

afonasev commented 3 years ago

Thx for issue! I will try fix it.