-
Notifications
You must be signed in to change notification settings - Fork 891
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
Add new DISABLE_SPLIT_LIST_WITH_COMMENT flag. #1177
Conversation
8c67e35
to
0a88806
Compare
cc @ptillet |
`DISABLE_SPLIT_LIST_WITH_COMMENT` is a new knob that changes the behavior of splitting a list when a comment is present inside the list. Before, we split a list containing a comment just like we split a list containing a trailing comma: Each element goes on its own line (unless `DISABLE_ENDING_COMMA_HEURISTIC` is true). Now, if `DISABLE_SPLIT_LIST_WITH_COMMENT` is true, we do not split every element of the list onto a new line just because there's a comment somewhere in the list. This mirrors the behavior of clang-format, and is useful for e.g. forming "logical groups" of elements in a list. Note: Upgrading will result in a behavioral change if you have `DISABLE_ENDING_COMMA_HEURISTIC` in your config. Before this version, this flag caused us not to split lists with a trailing comma *and* lists that contain comments. Now, if you set only that flag, we *will* split lists that contain comments. Set the new `DISABLE_SPLIT_LIST_WITH_COMMENT` flag to true to preserve the old behavior.
0a88806
to
bf301f5
Compare
I've add an option to yapf to do what we want for long lines, see google/yapf#1177. We can now have a real Python formatter, yay! To make this PR, I ran my modified yapf over the repository, then looked over the full diff. Where yapf was mangling the param list of long function decls/calls (mostly kernels), I manually added `#` to put linebreaks where we want. I fixed up other formatting too -- mostly adding or removing a trailing comma from lists. Overall, trailing `#` was sufficient to get formatting similar to our current code. I didn't have to disable yapf anywhere.
I've add an option to yapf to do what we want for long lines, see google/yapf#1177. We can now have a real Python formatter, yay! To make this PR, I ran my modified yapf over the repository, then looked over the full diff. Where yapf was mangling the param list of long function decls/calls (mostly kernels), I manually added `#` to put linebreaks where we want. I fixed up other formatting too -- mostly adding or removing a trailing comma from lists. Overall, trailing `#` was sufficient to get formatting similar to our current code. I didn't have to disable yapf anywhere.
I've add an option to yapf to do what we want for long lines, see google/yapf#1177. We can now have a real Python formatter, yay! To make this PR, I ran my modified yapf over the repository, then looked over the full diff. Where yapf was mangling the param list of long function decls/calls (mostly kernels), I manually added `#` to put linebreaks where we want. I fixed up other formatting too -- mostly adding or removing a trailing comma from lists. Overall, trailing `#` was sufficient to get formatting similar to our current code. I didn't have to disable yapf anywhere. --------- Co-authored-by: Phil Tillet <[email protected]>
CHANGELOG.md
Outdated
`DISABLE_ENDING_COMMA_HEURISTIC` in your config. Before this version, this | ||
flag caused us not to split lists with a trailing comma *and* lists that | ||
contain comments. Now, if you set only that flag, we *will* split lists | ||
that contain comments. Set the new `DISABLE_SPLIT_LIST_WITH_COMMENT` flag to |
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.
This confuses me. You say that with this flag:
we will split lists that contain comments
But isn't that exactly what this flag is supposed to prevent?
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 think it's right?
You say that with this flag:
we will split lists that contain comments
That's not what I intended to convey. In the context above, "this flag" refers to DISABLE_ENDING_COMMA_HEURISTIC
.
To be more clear, here's what changes.
-
Before:
- Default: split lists with a trailing comma or with comments.
DISABLE_ENDING_COMMA_HEURISTIC=true
, do not split lists with a trailing comma or with comments.
-
After:
- Default: Same as before.
DISABLE_ENDING_COMMA_HEURISTIC=true
andDISABLE_SPLIT_LIST_WITH_COMMENT=false
, do not split lists with trailing comma, but do split lists with comments. This is different than before.DISABLE_ENDING_COMMA_HEURISTIC=false
andDISABLE_SPLIT_LIST_WITH_COMMENT=true
, do split lists with a trailing comma, but do not split lists with comments. You used to get this behavior just by settingDISABLE_ENDING_COMMA_HEURISTIC=true
, but now you need to set two flags.- Both flags true: do not split lists with a trailing comma, and do not split lists with comments.
(I hope I got that right above.)
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.
Ah! Okay.
Could you add the interaction with DISABLE_ENDING_COMMA_HEURISTIC
in the README.md and style.py descriptions? I want to make sure people know about any any unforeseen side-effects. :-)
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.
Done, please have a look. And thanks again!
Thank you for the review! |
Write more in CHANGELOG.md, and add pointers to the changelog in README.md and style.py.
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.
Thank you for this excellent work. And also for adding documentation for DISABLE_SPLIT_LIST_WITH_COMMENT
. :-)
Woo, thank you for merging! |
Note to self: This branch is referred to in the Triton pre-commit, so I should not delete it. :) |
I've add an option to yapf to do what we want for long lines, see google/yapf#1177. We can now have a real Python formatter, yay! To make this PR, I ran my modified yapf over the repository, then looked over the full diff. Where yapf was mangling the param list of long function decls/calls (mostly kernels), I manually added `#` to put linebreaks where we want. I fixed up other formatting too -- mostly adding or removing a trailing comma from lists. Overall, trailing `#` was sufficient to get formatting similar to our current code. I didn't have to disable yapf anywhere. --------- Co-authored-by: Phil Tillet <[email protected]>
DISABLE_SPLIT_LIST_WITH_COMMENT
is a new knob that changes thebehavior of splitting a list when a comment is present inside the list.
Before, we split a list containing a comment just like we split a list
containing a trailing comma: Each element goes on its own line (unless
DISABLE_ENDING_COMMA_HEURISTIC
is true).Now, if
DISABLE_SPLIT_LIST_WITH_COMMENT
is true, we do not split everyelement of the list onto a new line just because there's a comment somewhere
in the list.
This mirrors the behavior of clang-format, and is useful for e.g. forming
"logical groups" of elements in a list.
Note: Upgrading will result in a behavioral change if you have
DISABLE_ENDING_COMMA_HEURISTIC
in your config. Before this version, thisflag caused us not to split lists with a trailing comma and lists that
contain comments. Now, if you set only that flag, we will split lists
that contain comments. Set the new
DISABLE_SPLIT_LIST_WITH_COMMENT
flag totrue to preserve the old behavior.