-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
F841
ignores redefinitions of local assignments
#6704
Comments
I see the same output here for Ruff and Flake8. Ruff:
Flake8:
What am I missing here? :) |
Sorry, my example is wrong, the trouble starts exactly as follows.
|
Thanks, though I still don't see F841 errors for Ruff or Flake8 with that code:
|
Yes, but normally you should see it, because the teams in line 3 have never been used :S |
There are a bunch of Pyflakes issues about this like PyCQA/pyflakes#498 or the parent issue PyCQA/pyflakes#715. It's not trivial because we need to handle cases like: a = 1
if ...:
a = 2
print(a) Or, above: def test():
if user.admin_user:
teams = user.teams.all()
if user.teams.filter(name="admin").exists():
print("admin")
else:
print("not admin")
if user.org_user:
# Redefined `teams`, unused.
teams = user.teams.all()
# But it _might_ be used here.
if teams.filter(booking=True).exists():
return self.filter(models.Q(booking__isnull=False))
return self.filter() Undecided on whether to keep this open as it does have parity with Pyflakes and this kind of branch analysis is probably a bigger project beyond this issue. |
F841
Not working properlyF841
ignores redefinitions of local assignments
It makes it very difficult for us to find the definitions that the developer overlooked in the ci/cd process. Thank you for the information and tagging. <3 |
I think Ruff should support this but it requires a branch sensitive analysis which Ruff doesn't support today |
While developing complex code in Django, I realised that F841 was not working properly.
I am leaving a small code example. under normal conditions flake8 says that the "teams" in this code are not used, but I do not encounter any warning in ruff.
Or even if it detects it, it shows the last one found, it must show all three
Ruff version: 0.0.285
The text was updated successfully, but these errors were encountered: