Format function and class definitions into a single line if its body is an ellipsis#6592
Conversation
PR Check ResultsBenchmarkLinuxWindows |
MichaReiser
left a comment
There was a problem hiding this comment.
This starts to looking good. I left a few comments that hopefully help to solve the TODOs. We have to use the new clause_body everywhere where we do block_indent(&body.format()) today (all compound statements). But we can do this once the class and function formatting is stable.
crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/top_level.pyi
Show resolved
Hide resolved
|
Wow, nice work. This shoots our typeshed compatibility up by more than 20%
|
|
I'm trying to work out why it formats class EllipsisWithLeadingComment:
# leading
... to class EllipsisWithLeadingComment: # leading
...Once that's sorted, it should be possible to do the same for every other clause body... |
Sounds good. Let me know if you want any help. |
57f6270 to
ebea2a9
Compare
a9bf9a0 to
68fe3f1
Compare
|
The logic for match statements seems different to other compound statements let mut last_case = first;
for case in cases_iter {
write!(
f,
[block_indent(&format_args!(
leading_alternate_branch_comments(
comments.leading(case),
last_case.body.last(),
),
case.format()
))]
)?;
last_case = case;
}I'm not quite sure how this would with |
|
Nice, this change is so cool. Thanks for working on it. Do we need to change the try formatting as well?
I understand this isn't needed on the ruff/crates/ruff_python_formatter/src/other/match_case.rs Lines 27 to 63 in 0cea497 |
|
I think the last thing now is to add the handling to the try statement ruff/crates/ruff_python_formatter/src/statement/stmt_try.rs Lines 136 to 143 in 0cea497 |
Summary
Formats
to
Closes #5822.
Test Plan
cargo test