mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-31 15:47:41 +00:00
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 https://github.com/astral-sh/ruff/issues/7448 Fixes https://github.com/astral-sh/ruff/issues/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 <micha@reiser.io>
This commit is contained in:
parent
67b043482a
commit
8f9753f58e
13 changed files with 652 additions and 124 deletions
|
@ -161,3 +161,14 @@ if True:
|
|||
+ "WARNING: Removing listed files. Do you really want to continue. yes/n)? "
|
||||
):
|
||||
pass
|
||||
|
||||
# https://github.com/astral-sh/ruff/issues/7448
|
||||
x = (
|
||||
# a
|
||||
not # b
|
||||
# c
|
||||
( # d
|
||||
# e
|
||||
True
|
||||
)
|
||||
)
|
||||
|
|
|
@ -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
|
||||
)
|
||||
)
|
|
@ -86,10 +86,6 @@ with (
|
|||
)
|
||||
): pass
|
||||
|
||||
with (a # trailing same line comment
|
||||
# trailing own line comment
|
||||
) as b: pass
|
||||
|
||||
with (
|
||||
a # trailing same line comment
|
||||
# trailing own line comment
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue