mirror of
https://github.com/astral-sh/ruff.git
synced 2025-08-03 10:23:11 +00:00
Formatter: Add test cases for comments after opening parentheses (#6420)
**Summary** I collected all examples of end-of-line comments after opening parentheses that i could think of so we get a comprehensive view at the state of their formatting (#6390). This PR intentionally only adds tests cases without any changes in formatting. We need to decide which exact formatting we want, ideally in terms of these test files, and implement this in follow-up PRs. ~~One stability check is still deactivated pending https://github.com/astral-sh/ruff/pull/6386.~~
This commit is contained in:
parent
39beeb61f7
commit
4811af0f0b
8 changed files with 842 additions and 1 deletions
53
crates/ruff_python_formatter/resources/test/fixtures/ruff/parentheses/nested.py
vendored
Normal file
53
crates/ruff_python_formatter/resources/test/fixtures/ruff/parentheses/nested.py
vendored
Normal file
|
@ -0,0 +1,53 @@
|
|||
a1 = f( # 1
|
||||
g( # 2
|
||||
)
|
||||
)
|
||||
a2 = f( # 1
|
||||
g( # 2
|
||||
x
|
||||
)
|
||||
)
|
||||
a3 = f(
|
||||
(
|
||||
#
|
||||
()
|
||||
)
|
||||
)
|
||||
|
||||
|
||||
call(
|
||||
a,
|
||||
b,
|
||||
[ # Empty because of
|
||||
]
|
||||
)
|
||||
|
||||
a = a + b + c + d + ( # Hello
|
||||
e + f + g
|
||||
)
|
||||
|
||||
a = int( # type: ignore
|
||||
int( # type: ignore
|
||||
int( # type: ignore
|
||||
6
|
||||
)
|
||||
)
|
||||
)
|
||||
|
||||
# Stability and correctness checks
|
||||
b1 = () - ( #
|
||||
)
|
||||
() - ( #
|
||||
)
|
||||
b2 = () - f( #
|
||||
)
|
||||
() - f( #
|
||||
)
|
||||
b3 = (
|
||||
#
|
||||
()
|
||||
)
|
||||
(
|
||||
#
|
||||
()
|
||||
)
|
|
@ -0,0 +1,86 @@
|
|||
# Opening parentheses end-of-line comment without a value in the parentheses
|
||||
|
||||
( # a 1
|
||||
)
|
||||
a2 = ( # a 2
|
||||
)
|
||||
a3 = f( # a 3
|
||||
)
|
||||
a4 = ( # a 4
|
||||
) = a4
|
||||
a5: List( # a 5
|
||||
) = 5
|
||||
|
||||
raise ( # b 1a
|
||||
)
|
||||
raise b1b from ( # b 1b
|
||||
)
|
||||
raise ( # b 1c
|
||||
) from b1c
|
||||
del ( # b 2
|
||||
)
|
||||
assert ( # b 3
|
||||
), ( #b 4
|
||||
)
|
||||
|
||||
def g():
|
||||
"""Statements that are only allowed in function bodies"""
|
||||
return ( # c 1
|
||||
)
|
||||
yield ( # c 2
|
||||
)
|
||||
async def h():
|
||||
"""Statements that are only allowed in async function bodies"""
|
||||
await ( # c 3
|
||||
)
|
||||
|
||||
with ( # d 1
|
||||
): pass
|
||||
match ( # d 2
|
||||
):
|
||||
case d2:
|
||||
pass
|
||||
match d3:
|
||||
case ( # d 3
|
||||
):
|
||||
pass
|
||||
while ( # d 4
|
||||
):
|
||||
pass
|
||||
if ( # d 5
|
||||
):
|
||||
pass
|
||||
elif ( # d 6
|
||||
):
|
||||
pass
|
||||
for ( # d 7
|
||||
) in ( # d 8
|
||||
):
|
||||
pass
|
||||
try:
|
||||
pass
|
||||
except ( # d 9
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def e1( # e 1
|
||||
): pass
|
||||
|
||||
|
||||
def e2() -> ( # e 2
|
||||
): pass
|
||||
|
||||
|
||||
class E3( # e 3
|
||||
): pass
|
||||
|
||||
|
||||
f1 = [ # f 1
|
||||
]
|
||||
[ # f 2
|
||||
]
|
||||
f3 = { # f3
|
||||
}
|
||||
{ # f 4
|
||||
}
|
|
@ -0,0 +1,108 @@
|
|||
# Opening parentheses end-of-line comment with value in the parentheses
|
||||
|
||||
( # a 1
|
||||
x)
|
||||
a2 = ( # a 2
|
||||
x)
|
||||
a3 = f( # a 3
|
||||
x)
|
||||
a4 = ( # a 4
|
||||
x) = a4
|
||||
a5: List( # a 5
|
||||
x) = 5
|
||||
|
||||
raise ( # b 1a
|
||||
x)
|
||||
raise b1b from ( # b 1b
|
||||
x)
|
||||
raise ( # b 1c
|
||||
x) from b1c
|
||||
del ( # b 2
|
||||
x)
|
||||
assert ( # b 3
|
||||
x), ( #b 4
|
||||
x)
|
||||
|
||||
def g():
|
||||
"""Statements that are only allowed in function bodies"""
|
||||
return ( # c 1
|
||||
x)
|
||||
yield ( # c 2
|
||||
x)
|
||||
async def h():
|
||||
"""Statements that are only allowed in async function bodies"""
|
||||
await ( # c 3
|
||||
x)
|
||||
|
||||
with ( # d 1
|
||||
x): pass
|
||||
match ( # d 2
|
||||
x):
|
||||
case d2:
|
||||
pass
|
||||
match d3:
|
||||
case ( # d 3
|
||||
x):
|
||||
pass
|
||||
while ( # d 4
|
||||
x):
|
||||
pass
|
||||
if ( # d 5
|
||||
x):
|
||||
pass
|
||||
elif ( # d 6
|
||||
y):
|
||||
pass
|
||||
for ( # d 7
|
||||
x) in ( # d 8
|
||||
y):
|
||||
pass
|
||||
try:
|
||||
pass
|
||||
except ( # d 9
|
||||
x
|
||||
):
|
||||
pass
|
||||
|
||||
|
||||
def e1( # e 1
|
||||
x): pass
|
||||
|
||||
|
||||
def e2() -> ( # e 2
|
||||
x): pass
|
||||
|
||||
|
||||
class E3( # e 3
|
||||
x): pass
|
||||
|
||||
|
||||
f1 = [ # f 1
|
||||
x]
|
||||
[ # f 2
|
||||
x]
|
||||
f3 = { # f3
|
||||
x}
|
||||
{ # f 4
|
||||
x}
|
||||
|
||||
|
||||
|
||||
# Non-empty parentheses: These are not allowed without a value
|
||||
def f1[ # f1
|
||||
T
|
||||
](): pass
|
||||
f2 = ( # f2
|
||||
i for i in range(10)
|
||||
)
|
||||
f3 = [ # f3
|
||||
i for i in range(10)
|
||||
]
|
||||
f4 = { # f4
|
||||
i for i in range(10)
|
||||
}
|
||||
f5 = { # f5
|
||||
i: i**2 for i in range(10)
|
||||
}
|
||||
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue