-
-
Notifications
You must be signed in to change notification settings - Fork 18.5k
STYLE: Add ruff check to avoid multiple with
statements
#53436
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
Comments
with
statements
Maybe in |
Thank you for telling me @snorfyang. Since I'm not sure, I'm tagging @MarcoGorelli. |
yup, that's right, along with the other ruff codes - PRs welcome if this interests anyone! if you add the code for this check to |
take |
Maybe a stupid question, but why would we want to disallow this globally? 2 with statements might have different scope |
It would still be possible to have two or more scopes, it is just the way to write them that would change. Look at Marco's comment here if you wish. |
They might refer to different Code parts though, not all with statements might exactly have the same length. |
I presume ruff has thought about this and they only recommend collapsing the 'with' statements if they have the same scope - should be fine, and it's one of the autofixable ones |
I still have concerns about readability, imo we should at least escape tests from this, since this reads terrible, I highlighted one such occurrence in the pr that is linked here |
it's a matter of preference I guess, if you don't like it then let's leave this one out, no worries, we don't need to enable all of ruff's checks 😃 let's close then, thanks all for the issue/discussion |
Currently, it is possible to nest multiple consecutive context managers in the code.
It can be avoided by adding the following to ruff checks:
https://beta.ruff.rs/docs/rules/multiple-with-statements/
This should be added to .pre-commit-config.yamlThe text was updated successfully, but these errors were encountered: