-
Notifications
You must be signed in to change notification settings - Fork 1.1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Comments outside expression parentheses (#7873)
<!-- Thank you for contributing to Ruff! To help us out with reviewing, please consider the following: - Does this pull request include a summary of the change? (See below.) - Does this pull request include a descriptive title? - Does this pull request include references to any relevant issues? --> ## Summary Fixes #7448 Fixes #7892 I've removed automatic dangling comment formatting, we're doing manual dangling comment formatting everywhere anyway (the assert-all-comments-formatted ensures this) and dangling comments would break the formatting there. ## Test Plan New test file. --------- Co-authored-by: Micha Reiser <[email protected]>
- Loading branch information
1 parent
67b0434
commit 8f9753f
Showing
13 changed files
with
652 additions
and
124 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
113 changes: 113 additions & 0 deletions
113
...hon_formatter/resources/test/fixtures/ruff/parentheses/expression_parentheses_comments.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,113 @@ | ||
list_with_parenthesized_elements1 = [ | ||
# comment leading outer | ||
( | ||
# comment leading inner | ||
1 + 2 # comment trailing inner | ||
) # comment trailing outer | ||
] | ||
|
||
list_with_parenthesized_elements2 = [ | ||
# leading outer | ||
(1 + 2) | ||
] | ||
list_with_parenthesized_elements3 = [ | ||
# leading outer | ||
(1 + 2) # trailing outer | ||
] | ||
list_with_parenthesized_elements4 = [ | ||
# leading outer | ||
(1 + 2), # trailing outer | ||
] | ||
list_with_parenthesized_elements5 = [ | ||
(1), # trailing outer | ||
(2), # trailing outer | ||
] | ||
|
||
nested_parentheses1 = ( | ||
( | ||
( | ||
1 | ||
) # i | ||
) # j | ||
) # k | ||
nested_parentheses2 = [ | ||
( | ||
( | ||
( | ||
1 | ||
) # i | ||
# i2 | ||
) # j | ||
# j2 | ||
) # k | ||
# k2 | ||
] | ||
nested_parentheses3 = ( | ||
( # a | ||
( # b | ||
1 | ||
) # i | ||
) # j | ||
) # k | ||
nested_parentheses4 = [ | ||
# a | ||
( # b | ||
# c | ||
( # d | ||
# e | ||
( #f | ||
1 | ||
) # i | ||
# i2 | ||
) # j | ||
# j2 | ||
) # k | ||
# k2 | ||
] | ||
|
||
|
||
x = ( | ||
# unary comment | ||
not | ||
# in-between comment | ||
( | ||
# leading inner | ||
"a" | ||
), | ||
not # in-between comment | ||
( | ||
# leading inner | ||
"b" | ||
), | ||
not | ||
( # in-between comment | ||
# leading inner | ||
"c" | ||
), | ||
# 1 | ||
not # 2 | ||
( # 3 | ||
# 4 | ||
"d" | ||
) | ||
) | ||
|
||
if ( | ||
# unary comment | ||
not | ||
# in-between comment | ||
( | ||
# leading inner | ||
1 | ||
) | ||
): | ||
pass | ||
|
||
# Make sure we keep a inside the parentheses | ||
# https://github.com/astral-sh/ruff/issues/7892 | ||
x = ( | ||
# a | ||
( # b | ||
1 | ||
) | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.