Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -169,3 +169,9 @@
# dangling before dot
.b # trailing end-of-line
)

# Regression test for https://github.com/astral-sh/ruff/issues/19350
variable = (
(something) # a comment
.fist_method("some string")
)
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,11 @@ impl NeedsParentheses for ExprAttribute {
context.comments().ranges(),
context.source(),
) {
OptionalParentheses::Never
if context.comments().has_trailing(self.value.as_ref()) {
Copy link
Member

@MichaReiser MichaReiser Sep 16, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We'll now also use the new layout if value is parenthesized and has a trailing comment like this

variable = (
    (something # a comment  
    ).fist_method("some string")
)

I think that's fine but it might be worth adding a few more tests.

For example, this snippet now gets formatted differently:

if (
    (something # a comment  
    ).fist_method("some string") # second comment
): pass

Overall, maybe add a few more permutations with multiple comments (or at least play with it in the playground)

OptionalParentheses::Multiline
} else {
OptionalParentheses::Never
}
} else {
self.value.needs_parentheses(self.into(), context)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -175,6 +175,12 @@ result = (
# dangling before dot
.b # trailing end-of-line
)

# Regression test for https://github.com/astral-sh/ruff/issues/19350
variable = (
(something) # a comment
.fist_method("some string")
)
```

## Output
Expand Down Expand Up @@ -328,4 +334,10 @@ result = (
# dangling before dot
.b # trailing end-of-line
)

# Regression test for https://github.com/astral-sh/ruff/issues/19350
variable = (
(something) # a comment
.fist_method("some string")
)
```
Loading