-
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
Lone unused import in if-statement should not get autofixed, or the if-statement should removed #9472
Comments
I think we have a rule for detecting and deleting empty type-checking blocks specifically, but we could make this part of the fix for the general "delete statement" logic. |
Ah you're right, Searching through the rules, I'm not seeing a rule for "empty/unnecessary if-statement" - even in cases where an if statement does have side-effects and removing it outright is dangerous, |
Is there interest in a PR for an "empty-if-statement" rule (potentially with an unsafe autofix)? I'd really love a way to catch empty Alternatively, RUF034 (#13218) could be expanded to check statements rather than just expressions to cover this case. This might also depend on if there should be an unsafe autofix (re: #13852). |
@gpauloski I could see such a rule to be useful, but we should think about its scope. E.g what about empty |
input
ruff --fix
problem
The latter is clearly awful code with fully redundant if statements, and the
sys
andTYPE_CHECKING
imports are in fact unused. There seems to be some custom logic for inserting thepass
statement, which I think should be removed and this case should not be treated as an auto-fix - since currently you need to manually fix it anyway (except currently you aren't warned about it, and have to check the diff).Other solutions include warning and/or autofixing*
if [...]: pass
statements. If they exist, they should be included by default.This is running a new, clean, venv with no config. Version 0.1.11
typing.TYPE_CHECKING
,sys.platform
,sys.version_info
and maybe a few more.The text was updated successfully, but these errors were encountered: