-
-
Notifications
You must be signed in to change notification settings - Fork 344
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
Disable ruff's COM812 #3144
Disable ruff's COM812 #3144
Conversation
I thought that #3044 was specifically for enabling this check, cannot say I support disabling it. I have noticed that some changes require multiple pre-commit runs as well, and while slightly annoying at times I don't think it merits disabling this rule entirely. |
I wasn't sure if there's other lints in that. But the alternatives are:
|
Now, if the rules created an edit loop that didn't resolve after a few iterations, then I might be for this change, but as is I think the commas apply in a way that makes the code a bit more readable, especially in cases with functions with several arguments. |
I'm not sure the alternative (reorder checks) works. We could duplicate the black check. This is because it seems ruff is whitespace sensitive. So take for instance this: nested_array = [
[
1,
2,
3,
]
] Under nested_array = [[
1,
2,
3,
]] Whereas
I'll change this to duplicating the |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #3144 +/- ##
=======================================
Coverage 99.62% 99.62%
=======================================
Files 124 124
Lines 18381 18381
Branches 1226 1226
=======================================
Hits 18312 18312
Misses 47 47
Partials 22 22 |
I personally prefer disabling COM812 over duplicating black. COM812 is perhaps nice, and ofc no reason to undo the changes in the PR, but I don't think it's worth having to duplicate black.
from the link:
So I think because you have a trailing comma on the If we can't make both ruff & black happy simultaneously I strongly think COM812 should be disabled, as we're otherwise gonna introduce headaches for LSP and/or IDE users that might be raising errors and/or autoformatting code. |
OK, so first... relitigating A5rocks/trio@disable-trailing-comma...86b17b2 Then I ran A5rocks/trio@86b17b2...6ac28c9 Interestingly, there's a decently large diff combining the two commits above. I won't make a PR for this because formatting really doesn't matter that much: A5rocks/trio@disable-trailing-comma...A5rocks:trio:commaless For reference, here's the code snippet that required two cycles: RaisesGroup = ...
Matcher = ...
def f() -> None:
with RaisesGroup(
Matcher(ValueError, "error text", lambda e: isinstance(e.__context__, KeyError))
):
...
Note: I'm pretty sure this is a line length thing so I don't know if a 3 cycle input is possible, and this kind of input is likely rare. I was expecting to be disappointed with the changes COM812 gives, but the changes are... fine. However, very few of the changes from COM812 (second link above) feel like they'd affect a diff: how much are we really modifying function signatures? I don't think changes other than that are useful. I still think it should be disabled but I'm less sure of myself now... In isolation I think it works well and if it didn't conflict with
Not sure how I tested this before but it actually does work with the trailing comma on |
yeah let's go with disabling it then. No shame in trying something out and taking it back after deliberation, better than being overly afraid of doing stuff because we don't wanna change our minds :) You can also remove the extra black run from |
Yea, I understand disabling this now. That is very unfortunate it doesn't play well with black. |
95679fb
to
b0dd931
Compare
"SIM117", # multiple-with-statements (messes up lots of context-based stuff and looks bad) | ||
|
||
# conflicts with formatter (ruff recommends these be disabled) | ||
"COM812", |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does Ruff have human-readable rule names? I thought it did... If so, I'd rather use those over some alphanumeric contextless IDs.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think it does, astral-sh/ruff#1773 is still open (but I haven't read through it)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
ye they still can't be used ~anywhere
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
bumping/clarifying my previous comment:
You can also remove the extra black run from gen_exports.py introduced in #3044
https://github.com/CoolCat467/trio/blob/30babafa732799d6730fe5936c5ddbe8f453ad12/src/trio/_tools/gen_exports.py#L194-L197
gen_exports.py
currently runs black->ruff->black, which shouldn't be necessary without COM812
Ruff's documentation recommends this be disabled with their formatter. I assume that advice holds for
black
too. The other rule they recommend disabling isISC001
which I don't think black has trouble with.I don't see a better way to keep this up to date, but the way I noticed this probably works. I was making changes and pre-commit was making me run git commit thrice, as the
ruff
autofixes didn't pass the next round ofblack
. The sequence was git commit:black
->ruff
(because ordering), then git commit:black
, then git commit: it actually worked.