-
Notifications
You must be signed in to change notification settings - Fork 1k
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
PERF102 - False Positive with Poorly Named Variables #5692
Labels
bug
Something isn't working
Comments
Skylion007
changed the title
PERF102 - False Positive + Bad Fix
PERF102 - False Positive with Poorly Named Variables
Jul 11, 2023
Yeah we can support this. |
Wow that's madness :) We should add a rule that checks for usage of |
Yeah, I've seen this kind of usage in the wild especially in comprehensions for one off variables. |
|
charliermarsh
added a commit
that referenced
this issue
Jul 14, 2023
## Summary `PERF102` looks for unused keys or values in `dict.items()` calls, and suggests instead using `dict.keys()` or `dict.values()`. Previously, this check determined usage by looking for underscore-prefixed variables. However, we can use the semantic model to actually detect whether a variable is used. This has two nice effects: 1. We avoid odd false-positives whereby underscore-prefixed variables are actually used. 2. We can catch more cases (fewer false-negatives) by detecting unused loop variables that _aren't_ underscore-prefixed. Closes #5692.
evanrittenhouse
pushed a commit
to evanrittenhouse/ruff
that referenced
this issue
Jul 19, 2023
…ral-sh#5763) ## Summary `PERF102` looks for unused keys or values in `dict.items()` calls, and suggests instead using `dict.keys()` or `dict.values()`. Previously, this check determined usage by looking for underscore-prefixed variables. However, we can use the semantic model to actually detect whether a variable is used. This has two nice effects: 1. We avoid odd false-positives whereby underscore-prefixed variables are actually used. 2. We can catch more cases (fewer false-negatives) by detecting unused loop variables that _aren't_ underscore-prefixed. Closes astral-sh#5692.
konstin
pushed a commit
that referenced
this issue
Jul 19, 2023
## Summary `PERF102` looks for unused keys or values in `dict.items()` calls, and suggests instead using `dict.keys()` or `dict.values()`. Previously, this check determined usage by looking for underscore-prefixed variables. However, we can use the semantic model to actually detect whether a variable is used. This has two nice effects: 1. We avoid odd false-positives whereby underscore-prefixed variables are actually used. 2. We can catch more cases (fewer false-negatives) by detecting unused loop variables that _aren't_ underscore-prefixed. Closes #5692.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
This code snippit is from sympy/matrices/common.py, this uses the latest stable ruff version and just has PERF102 manually selected using the command
ruff --select PERF --fix .
I know that the
_
prefix is often used to look for variables that should be unused in a loop, but ruff should check if the variable is actually unused before autofixing it to prevent bugprone autofixes. It should at least handle this trivial case.The text was updated successfully, but these errors were encountered: