-
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
Clean up unused variables after fixes #6254
Comments
Thanks for the report! Seems reasonable to me although it may be non-trivial. |
I believe this works as expected, assuming you enable the right set of rules: We like to treat each fix as independent. Here, the import contextlib
def f():
x = None
with contextlib.suppress(AttributeError):
x = func_that_might_throw()
return x Then the import contextlib
def f():
x = None
with contextlib.suppress(AttributeError):
return func_that_might_throw() Then the import contextlib
def f():
with contextlib.suppress(AttributeError):
return func_that_might_throw() (This all happens in one Perhaps you have |
Ahh, @charliermarsh is correct. unfixable = ["B007", "ERA001", "F841", "RUF100"] We disabled autofix on |
@tylerlaprade I agree that seems like a fair use-case. We probably don't want to resolve this just for this specific rule though, instead we should work on a general solution that checks for unused variables introduced by an autofix. Would you mind if I retitle this issue? |
Yes, please do! I'm glad this could potentially turn out to be more generally applicable than just a single rule. |
SIM105
should clean up unused variable after refactor
In the meantime, for this use-case, I'd recommend leaving |
Yes, that's a good suggestion, thank you Zanie! |
Ah, no luck - that same flag is used for the recursive fixes, so |
I think the suggestion was to leave you with a setup such that unused variables would be removed when running via the CLI, but not when running in the editor (which could happen "by accident"). |
is getting simplified to
If this is the first time we've seen
x
, can we clean up the null assignment?The text was updated successfully, but these errors were encountered: