-
-
Notifications
You must be signed in to change notification settings - Fork 54
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
Ensure variable is bound in FURB127 #47
Comments
Thank you for mentioning this. From the user perspective it might be a bit annoying to fix a certain line, only to have it complain about something else when you run it again, but from a developer perspective, this is hard to maintain. There are a lot of checks, and only more to come. If we start to have checks which depend on, or otherwise relate to another check, we risk having more fragile and harder to maintain checks. I like to think that each check is isolated, completely ignorant that any other check exists, except for itself. This reduces the amount of things you need to fix if something breaks. In short, this is a minor side effect of having isolated checks which don't know about each other, and sometimes step on each other's toes. Hopefully that answers your question! |
My point is the second one is wrong (and the first check just happens to force you into the second situation and makes it more common). If sysconfig does not have the attribute, it errors out and skips the redefinition. So if you remove the first definition, this variable might never be defined. |
You're right, I did not pick up on that. Here is a MVP that shows it better (IMO): from pathlib import Path
from contextlib import suppress, nullcontext
with suppress(FileNotFoundError):
contents = Path("invalid filename").read_text()
print(contents)
# vs
with nullcontext():
contents2 = Path("README.md").read_text()
print(contents2) In this example, |
Also, this made me realize that there is a different bug in the FURB107 check, in that |
That's nice, actually; |
I have fixed the bare exception The slightly harder issue is disabling this check if x = 1
with suppress(Exception):
x = 2 Although contrived, there is no exception being raised here, though there is no good way of detecting that. This raises a different concern about other context managers which capture exceptions, leaving A better approach would be to emit a warning only if we know I think our best option is to just skip emitting an error if we encounter |
Didn't mean to close this |
This was happy, just reporting a cleanup:
But after making the cleanup:
In this case, it's not a huge deal (this is kind of ugly anyway so I'll probably rewrite it later), just thought I'd point it out if it's something you think is fixable and worth fixing.
The text was updated successfully, but these errors were encountered: