Skip to content

Commit

Permalink
Improve comments around Arguments handling in classes (#6310)
Browse files Browse the repository at this point in the history
## Summary

Based on the confusion here:
#6274 (comment).

I looked into moving this logic into `placement.rs`, but I think it's
trickier than it may appear.
  • Loading branch information
charliermarsh authored Aug 3, 2023
1 parent 2fa5087 commit b3f3529
Showing 1 changed file with 26 additions and 6 deletions.
32 changes: 26 additions & 6 deletions crates/ruff_python_formatter/src/statement/stmt_class_def.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,28 +64,48 @@ impl FormatNodeRule<StmtClassDef> for FormatStmtClassDef {
}

if let Some(arguments) = arguments.as_deref() {
// Drop empty parentheses, e.g., in:
// Drop empty the arguments node entirely (i.e., remove the parentheses) if it is empty,
// e.g., given:
// ```python
// class A():
// ...
// ```
//
// However, preserve any dangling end-of-line comments, e.g., in:
// Format as:
// ```python
// class A:
// ...
// ```
//
// However, preserve any dangling end-of-line comments, e.g., given:
// ```python
// class A( # comment
// ):
// ...
//
// If the arguments contain any dangling own-line comments, we retain the parentheses,
// e.g., in:
// Format as:
// ```python
// class A: # comment
// ...
// ```
//
// However, the arguments contain any dangling own-line comments, we retain the
// parentheses, e.g., given:
// ```python
// class A( # comment
// # comment
// ):
// ...
// ```
//
// Format as:
// ```python
// class A( # comment
// # comment
// ):
// ...
// ```
if arguments.args.is_empty()
&& arguments.keywords.is_empty()
if arguments.is_empty()
&& comments
.dangling_comments(arguments)
.iter()
Expand Down

0 comments on commit b3f3529

Please sign in to comment.