Use `pass` over ellipsis in non-function/class contexts (#8049)

Split out of #8044: In preview style, ellipsis are also collapsed in
non-stub files. This should only affect function/class contexts since
for other statements stub are generally not used. I've updated our tests
to use `pass` instead to reflect this, which makes tracking the preview
style changes much easier.
This commit is contained in:
konsti 2023-10-19 11:11:17 +02:00 committed by GitHub
parent 693f957b90
commit 67b043482a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
24 changed files with 294 additions and 294 deletions

View File

@ -75,7 +75,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & aaaaaaaaaaaaaaaaaaaaaaaaaa: ] & aaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -84,7 +84,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: ] & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
# Right only can break # Right only can break
if aaaaaaaaaaaaaaaaaaaaaaaaaa & [ if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
@ -94,7 +94,7 @@ if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & [ if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -103,7 +103,7 @@ if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
# Left or right can break # Left or right can break
@ -114,7 +114,7 @@ if [2222, 333] & [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -123,7 +123,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & [2222, 333]: ] & [2222, 333]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -132,7 +132,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & [fffffffffffffffff, gggggggggggggggggggg, hhhhhhhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjj]: ] & [fffffffffffffffff, gggggggggggggggggggg, hhhhhhhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjj]:
... pass
if ( if (
# comment # comment
@ -152,7 +152,7 @@ if (
]: ]:
pass pass
... pass
# Nesting # Nesting
if (aaaa + b) & [ if (aaaa + b) & [
@ -162,7 +162,7 @@ if (aaaa + b) & [
iiiiiiiiiiiiiiii, iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj, jjjjjjjjjjjjj,
]: ]:
... pass
if [ if [
fffffffffffffffff, fffffffffffffffff,
@ -171,7 +171,7 @@ if [
iiiiiiiiiiiiiiii, iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj, jjjjjjjjjjjjj,
] & (a + b): ] & (a + b):
... pass
if [ if [
@ -185,7 +185,7 @@ if [
a a
+ b + b
): ):
... pass
if ( if (
[ [
@ -199,7 +199,7 @@ if (
# comment # comment
a + b a + b
): ):
... pass
# Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py # Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py

View File

@ -16,7 +16,7 @@ if (
and self._returncode and self._returncode
and self._proc.poll() and self._proc.poll()
): ):
... pass
if ( if (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@ -26,14 +26,14 @@ if (
and aaaaaaaaaaaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaaaaaaaaaaa
and aaaaaaaaaaaaaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
): ):
... pass
if ( if (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
and aaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaa
): ):
... pass
if [2222, 333] and [ if [2222, 333] and [
@ -43,7 +43,7 @@ if [2222, 333] and [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,

View File

@ -65,7 +65,7 @@ d3 = "d"[
# Spacing around the colon(s) # Spacing around the colon(s)
def a(): def a():
... pass
e00 = "e"[:] e00 = "e"[:]
e01 = "e"[:1] e01 = "e"[:1]

View File

@ -139,18 +139,18 @@ if not \
# Regression: https://github.com/astral-sh/ruff/issues/5338 # Regression: https://github.com/astral-sh/ruff/issues/5338
if a and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: if a and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
if ( if (
not not
# comment # comment
a): a):
... pass
if ( if (
not # comment not # comment
a): a):
... pass
# Regression test for: https://github.com/astral-sh/ruff/issues/7423 # Regression test for: https://github.com/astral-sh/ruff/issues/7423
if True: if True:

View File

@ -51,7 +51,7 @@ aaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbb
for converter in connection.ops.get_db_converters( for converter in connection.ops.get_db_converters(
expression expression
) + expression.get_db_converters(connection): ) + expression.get_db_converters(connection):
... pass
aaa = ( aaa = (

View File

@ -15,23 +15,23 @@ for aVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAnd
pass pass
else: else:
... pass
for ( for (
x, x,
y, y,
) in z: # comment ) in z: # comment
... pass
# remove brackets around x,y but keep them around z,w # remove brackets around x,y but keep them around z,w
for (x, y) in (z, w): for (x, y) in (z, w):
... pass
# type comment # type comment
for x in (): # type: int for x in (): # type: int
... pass
# Tuple parentheses for iterable. # Tuple parentheses for iterable.
for x in 1, 2, 3: for x in 1, 2, 3:

View File

@ -19,12 +19,12 @@ else: # 12 trailing else condition
if x == y: if x == y:
if y == z: if y == z:
... pass
if a == b: if a == b:
... pass
else: # trailing comment else: # trailing comment
... pass
# trailing else comment # trailing else comment
@ -34,11 +34,11 @@ elif aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
2222222222222222222222, 2222222222222222222222,
3333333333 3333333333
]: ]:
... pass
else: else:
... pass
# Regression test: Don't drop the trailing comment by associating it with the elif # Regression test: Don't drop the trailing comment by associating it with the elif
# instead of the else. # instead of the else.

View File

@ -206,9 +206,9 @@ match pattern_singleton:
case ( case (
True # trailing True # trailing
): ):
... pass
case False: case False:
... pass
match foo: match foo:
@ -406,39 +406,39 @@ match pattern_match_class:
case Point2D( case Point2D(
# own line # own line
): ):
... pass
case ( case (
Point2D Point2D
# own line # own line
() ()
): ):
... pass
case Point2D( # end of line line case Point2D( # end of line line
): ):
... pass
case Point2D( # end of line case Point2D( # end of line
0, 0 0, 0
): ):
... pass
case Point2D(0, 0): case Point2D(0, 0):
... pass
case Point2D( case Point2D(
( # end of line ( # end of line
# own line # own line
0 0
), 0): ), 0):
... pass
case Point3D(x=0, y=0, z=000000000000000000000000000000000000000000000000000000000000000000000000000000000): case Point3D(x=0, y=0, z=000000000000000000000000000000000000000000000000000000000000000000000000000000000):
... pass
case Bar(0, a=None, b="hello"): case Bar(0, a=None, b="hello"):
... pass
case FooBar(# leading case FooBar(# leading
# leading # leading
@ -449,7 +449,7 @@ match pattern_match_class:
# trailing # trailing
# trailing # trailing
): ):
... pass
case A( case A(
b # b b # b
@ -481,26 +481,26 @@ match pattern_match_or:
# own line 4 # own line 4
c # trailing 5 c # trailing 5
): ):
... pass
case ( case (
(a) (a)
| # trailing | # trailing
( b ) ( b )
): ):
... pass
case (a|b|c): case (a|b|c):
... pass
case foo | bar | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh: case foo | bar | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:
... pass
case ( # end of line case ( # end of line
a | b a | b
# own line # own line
): ):
... pass
# Single-element tuples. # Single-element tuples.

View File

@ -1,72 +1,72 @@
try: try:
... pass
except: except:
... pass
try: try:
... pass
except (KeyError): # should remove brackets and be a single line except (KeyError): # should remove brackets and be a single line
... pass
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except (Exception, ValueError) as exc: # except line except (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except KeyError as key: # except line 2 except KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# with line breaks # with line breaks
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except (Exception, ValueError) as exc: # except line except (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except KeyError as key: # except line 2 except KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# with line breaks # with line breaks
try: try:
... pass
except: except:
... pass
try: try:
... pass
except (Exception, Exception, Exception, Exception, Exception, Exception, Exception) as exc: # splits exception over multiple lines except (Exception, Exception, Exception, Exception, Exception, Exception, Exception) as exc: # splits exception over multiple lines
... pass
try: try:
... pass
except: except:
a = 10 # trailing comment1 a = 10 # trailing comment1
b = 11 # trailing comment2 b = 11 # trailing comment2
@ -74,21 +74,21 @@ except:
# try/except*, mostly the same as try # try/except*, mostly the same as try
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except* (Exception, ValueError) as exc: # except line except* (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except* KeyError as key: # except line 2 except* KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# try and try star are statements with body # try and try star are statements with body
# Minimized from https://github.com/python/cpython/blob/99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1/Lib/getpass.py#L68-L91 # Minimized from https://github.com/python/cpython/blob/99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1/Lib/getpass.py#L68-L91

View File

@ -15,7 +15,7 @@ while aVeryLongConditionThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGo
pass pass
else: else:
... pass
while ( while (
some_condition(unformatted, args) and anotherCondition or aThirdCondition some_condition(unformatted, args) and anotherCondition or aThirdCondition

View File

@ -1,16 +1,16 @@
with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
# trailing # trailing
with a, a: # after colon with a, a: # after colon
... pass
# trailing # trailing
with ( with (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
): ):
... pass
# trailing # trailing
@ -19,7 +19,7 @@ with (
, # comma , # comma
b # c b # c
): # colon ): # colon
... pass
with ( with (
@ -30,7 +30,7 @@ with (
, # comma , # comma
c # c c # c
): # colon ): # colon
... # body pass # body
# body trailing own # body trailing own
with ( with (
@ -42,14 +42,14 @@ with (
with (a,): # magic trailing comma with (a,): # magic trailing comma
... pass
with (a): # should remove brackets with (a): # should remove brackets
... pass
with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as c: with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as c:
... pass
# currently unparsable by black: https://github.com/psf/black/issues/3678 # currently unparsable by black: https://github.com/psf/black/issues/3678
@ -60,45 +60,45 @@ with (a, *b):
with ( with (
# leading comment # leading comment
a) as b: ... a) as b: pass
with ( with (
# leading comment # leading comment
a as b a as b
): ... ): pass
with ( with (
a as b a as b
# trailing comment # trailing comment
): ... ): pass
with ( with (
a as ( a as (
# leading comment # leading comment
b b
) )
): ... ): pass
with ( with (
a as ( a as (
b b
# trailing comment # trailing comment
) )
): ... ): pass
with (a # trailing same line comment with (a # trailing same line comment
# trailing own line comment # trailing own line comment
) as b: ... ) as b: pass
with ( with (
a # trailing same line comment a # trailing same line comment
# trailing own line comment # trailing own line comment
as b as b
): ... ): pass
with (a # trailing same line comment with (a # trailing same line comment
# trailing own line comment # trailing own line comment
) as b: ... ) as b: pass
with ( with (
(a (a
@ -106,7 +106,7 @@ with (
) )
as # trailing as same line comment as # trailing as same line comment
b # trailing b same line comment b # trailing b same line comment
): ... ): pass
with ( with (
# comment # comment
@ -157,7 +157,7 @@ with (
CtxManager2() as example2, CtxManager2() as example2,
CtxManager2() as example2, CtxManager2() as example2,
): ):
... pass
with [ with [
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@ -165,7 +165,7 @@ with [
"cccccccccccccccccccccccccccccccccccccccccc", "cccccccccccccccccccccccccccccccccccccccccc",
dddddddddddddddddddddddddddddddd, dddddddddddddddddddddddddddddddd,
] as example1, aaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccccccc + ddddddddddddddddd as example2, CtxManager222222222222222() as example2: ] as example1, aaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccccccc + ddddddddddddddddd as example2, CtxManager222222222222222() as example2:
... pass
# Comments on open parentheses # Comments on open parentheses
with ( # comment with ( # comment
@ -173,7 +173,7 @@ with ( # comment
CtxManager2() as example2, CtxManager2() as example2,
CtxManager3() as example3, CtxManager3() as example3,
): ):
... pass
with ( # outer comment with ( # outer comment
( # inner comment ( # inner comment
@ -182,25 +182,25 @@ with ( # outer comment
CtxManager2() as example2, CtxManager2() as example2,
CtxManager3() as example3, CtxManager3() as example3,
): ):
... pass
with ( # outer comment with ( # outer comment
CtxManager() CtxManager()
) as example: ) as example:
... pass
with ( # outer comment with ( # outer comment
CtxManager() CtxManager()
) as example, ( # inner comment ) as example, ( # inner comment
CtxManager2() CtxManager2()
) as example2: ) as example2:
... pass
with ( # outer comment with ( # outer comment
CtxManager1(), CtxManager1(),
CtxManager2(), CtxManager2(),
) as example: ) as example:
... pass
with ( # outer comment with ( # outer comment
( # inner comment ( # inner comment
@ -208,7 +208,7 @@ with ( # outer comment
), ),
CtxManager2(), CtxManager2(),
) as example: ) as example:
... pass
# Breaking of with items. # Breaking of with items.
with (test # bar with (test # bar

View File

@ -17,7 +17,7 @@ class Test:
c = 30 c = 30
while a == 10: while a == 10:
... print(a)
# trailing comment with one line before # trailing comment with one line before
@ -26,7 +26,7 @@ while a == 10:
d = 40 d = 40
while b == 20: while b == 20:
... print(b)
# no empty line before # no empty line before
e = 50 # one empty line before e = 50 # one empty line before

View File

@ -81,7 +81,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & aaaaaaaaaaaaaaaaaaaaaaaaaa: ] & aaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -90,7 +90,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: ] & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
# Right only can break # Right only can break
if aaaaaaaaaaaaaaaaaaaaaaaaaa & [ if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
@ -100,7 +100,7 @@ if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & [ if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -109,7 +109,7 @@ if aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
# Left or right can break # Left or right can break
@ -120,7 +120,7 @@ if [2222, 333] & [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -129,7 +129,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & [2222, 333]: ] & [2222, 333]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -138,7 +138,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & [fffffffffffffffff, gggggggggggggggggggg, hhhhhhhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjj]: ] & [fffffffffffffffff, gggggggggggggggggggg, hhhhhhhhhhhhhhhhhhhhh, iiiiiiiiiiiiiiii, jjjjjjjjjjjjj]:
... pass
if ( if (
# comment # comment
@ -158,7 +158,7 @@ if (
]: ]:
pass pass
... pass
# Nesting # Nesting
if (aaaa + b) & [ if (aaaa + b) & [
@ -168,7 +168,7 @@ if (aaaa + b) & [
iiiiiiiiiiiiiiii, iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj, jjjjjjjjjjjjj,
]: ]:
... pass
if [ if [
fffffffffffffffff, fffffffffffffffff,
@ -177,7 +177,7 @@ if [
iiiiiiiiiiiiiiii, iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj, jjjjjjjjjjjjj,
] & (a + b): ] & (a + b):
... pass
if [ if [
@ -191,7 +191,7 @@ if [
a a
+ b + b
): ):
... pass
if ( if (
[ [
@ -205,7 +205,7 @@ if (
# comment # comment
a + b a + b
): ):
... pass
# Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py # Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py
@ -532,7 +532,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & aaaaaaaaaaaaaaaaaaaaaaaaaa: ] & aaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
if ( if (
[ [
@ -544,7 +544,7 @@ if (
] ]
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
): ):
... pass
# Right only can break # Right only can break
if aaaaaaaaaaaaaaaaaaaaaaaaaa & [ if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
@ -554,7 +554,7 @@ if aaaaaaaaaaaaaaaaaaaaaaaaaa & [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if ( if (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@ -566,7 +566,7 @@ if (
eeeeeeeeee, eeeeeeeeee,
] ]
): ):
... pass
# Left or right can break # Left or right can break
@ -577,7 +577,7 @@ if [2222, 333] & [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -586,7 +586,7 @@ if [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
] & [2222, 333]: ] & [2222, 333]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -601,7 +601,7 @@ if [
iiiiiiiiiiiiiiii, iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj, jjjjjjjjjjjjj,
]: ]:
... pass
if ( if (
# comment # comment
@ -621,7 +621,7 @@ if (
]: ]:
pass pass
... pass
# Nesting # Nesting
if (aaaa + b) & [ if (aaaa + b) & [
@ -631,7 +631,7 @@ if (aaaa + b) & [
iiiiiiiiiiiiiiii, iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj, jjjjjjjjjjjjj,
]: ]:
... pass
if [ if [
fffffffffffffffff, fffffffffffffffff,
@ -640,7 +640,7 @@ if [
iiiiiiiiiiiiiiii, iiiiiiiiiiiiiiii,
jjjjjjjjjjjjj, jjjjjjjjjjjjj,
] & (a + b): ] & (a + b):
... pass
if [ if [
@ -653,7 +653,7 @@ if [
# comment # comment
a + b a + b
): ):
... pass
if ( if (
[ [
@ -667,7 +667,7 @@ if (
# comment # comment
a + b a + b
): ):
... pass
# Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py # Unstable formatting in https://github.com/realtyem/synapse-unraid/blob/unraid_develop/synapse/handlers/presence.py

View File

@ -22,7 +22,7 @@ if (
and self._returncode and self._returncode
and self._proc.poll() and self._proc.poll()
): ):
... pass
if ( if (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@ -32,14 +32,14 @@ if (
and aaaaaaaaaaaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaaaaaaaaaaa
and aaaaaaaaaaaaaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
): ):
... pass
if ( if (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
and aaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaa
): ):
... pass
if [2222, 333] and [ if [2222, 333] and [
@ -49,7 +49,7 @@ if [2222, 333] and [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,
@ -213,7 +213,7 @@ if (
and self._returncode and self._returncode
and self._proc.poll() and self._proc.poll()
): ):
... pass
if ( if (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
@ -223,14 +223,14 @@ if (
and aaaaaaaaaaaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaaaaaaaaaaa
and aaaaaaaaaaaaaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaaaaaaaaaaaaa
): ):
... pass
if ( if (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaas
and aaaaaaaaaaaaaaaaa and aaaaaaaaaaaaaaaaa
): ):
... pass
if [2222, 333] and [ if [2222, 333] and [
@ -240,7 +240,7 @@ if [2222, 333] and [
dddddddddddddddddddd, dddddddddddddddddddd,
eeeeeeeeee, eeeeeeeeee,
]: ]:
... pass
if [ if [
aaaaaaaaaaaaa, aaaaaaaaaaaaa,

View File

@ -71,7 +71,7 @@ d3 = "d"[
# Spacing around the colon(s) # Spacing around the colon(s)
def a(): def a():
... pass
e00 = "e"[:] e00 = "e"[:]
e01 = "e"[:1] e01 = "e"[:1]
@ -184,7 +184,7 @@ d3 = "d"[
# Spacing around the colon(s) # Spacing around the colon(s)
def a(): def a():
... pass
e00 = "e"[:] e00 = "e"[:]

View File

@ -145,18 +145,18 @@ if not \
# Regression: https://github.com/astral-sh/ruff/issues/5338 # Regression: https://github.com/astral-sh/ruff/issues/5338
if a and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: if a and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
if ( if (
not not
# comment # comment
a): a):
... pass
if ( if (
not # comment not # comment
a): a):
... pass
# Regression test for: https://github.com/astral-sh/ruff/issues/7423 # Regression test for: https://github.com/astral-sh/ruff/issues/7423
if True: if True:
@ -324,17 +324,17 @@ if (
and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa and not aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
& aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa & aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa
): ):
... pass
if ( if (
not not
# comment # comment
a a
): ):
... pass
if not a: # comment if not a: # comment
... pass
# Regression test for: https://github.com/astral-sh/ruff/issues/7423 # Regression test for: https://github.com/astral-sh/ruff/issues/7423
if True: if True:

View File

@ -57,7 +57,7 @@ aaaaaaaa = aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbb
for converter in connection.ops.get_db_converters( for converter in connection.ops.get_db_converters(
expression expression
) + expression.get_db_converters(connection): ) + expression.get_db_converters(connection):
... pass
aaa = ( aaa = (
@ -161,7 +161,7 @@ aaaaaaaa = (
for converter in connection.ops.get_db_converters( for converter in connection.ops.get_db_converters(
expression expression
) + expression.get_db_converters(connection): ) + expression.get_db_converters(connection):
... pass
aaa = ( aaa = (

View File

@ -21,23 +21,23 @@ for aVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAnd
pass pass
else: else:
... pass
for ( for (
x, x,
y, y,
) in z: # comment ) in z: # comment
... pass
# remove brackets around x,y but keep them around z,w # remove brackets around x,y but keep them around z,w
for (x, y) in (z, w): for (x, y) in (z, w):
... pass
# type comment # type comment
for x in (): # type: int for x in (): # type: int
... pass
# Tuple parentheses for iterable. # Tuple parentheses for iterable.
for x in 1, 2, 3: for x in 1, 2, 3:
@ -97,23 +97,23 @@ for aVeryLongNameThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGoesOnAnd
pass pass
else: else:
... pass
for ( for (
x, x,
y, y,
) in z: # comment ) in z: # comment
... pass
# remove brackets around x,y but keep them around z,w # remove brackets around x,y but keep them around z,w
for x, y in (z, w): for x, y in (z, w):
... pass
# type comment # type comment
for x in (): # type: int for x in (): # type: int
... pass
# Tuple parentheses for iterable. # Tuple parentheses for iterable.
for x in 1, 2, 3: for x in 1, 2, 3:

View File

@ -25,12 +25,12 @@ else: # 12 trailing else condition
if x == y: if x == y:
if y == z: if y == z:
... pass
if a == b: if a == b:
... pass
else: # trailing comment else: # trailing comment
... pass
# trailing else comment # trailing else comment
@ -40,11 +40,11 @@ elif aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
2222222222222222222222, 2222222222222222222222,
3333333333 3333333333
]: ]:
... pass
else: else:
... pass
# Regression test: Don't drop the trailing comment by associating it with the elif # Regression test: Don't drop the trailing comment by associating it with the elif
# instead of the else. # instead of the else.
@ -325,12 +325,12 @@ else: # 12 trailing else condition
if x == y: if x == y:
if y == z: if y == z:
... pass
if a == b: if a == b:
... pass
else: # trailing comment else: # trailing comment
... pass
# trailing else comment # trailing else comment
@ -340,11 +340,11 @@ elif aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa +
2222222222222222222222, 2222222222222222222222,
3333333333, 3333333333,
]: ]:
... pass
else: else:
... pass
# Regression test: Don't drop the trailing comment by associating it with the elif # Regression test: Don't drop the trailing comment by associating it with the elif
# instead of the else. # instead of the else.

View File

@ -212,9 +212,9 @@ match pattern_singleton:
case ( case (
True # trailing True # trailing
): ):
... pass
case False: case False:
... pass
match foo: match foo:
@ -412,39 +412,39 @@ match pattern_match_class:
case Point2D( case Point2D(
# own line # own line
): ):
... pass
case ( case (
Point2D Point2D
# own line # own line
() ()
): ):
... pass
case Point2D( # end of line line case Point2D( # end of line line
): ):
... pass
case Point2D( # end of line case Point2D( # end of line
0, 0 0, 0
): ):
... pass
case Point2D(0, 0): case Point2D(0, 0):
... pass
case Point2D( case Point2D(
( # end of line ( # end of line
# own line # own line
0 0
), 0): ), 0):
... pass
case Point3D(x=0, y=0, z=000000000000000000000000000000000000000000000000000000000000000000000000000000000): case Point3D(x=0, y=0, z=000000000000000000000000000000000000000000000000000000000000000000000000000000000):
... pass
case Bar(0, a=None, b="hello"): case Bar(0, a=None, b="hello"):
... pass
case FooBar(# leading case FooBar(# leading
# leading # leading
@ -455,7 +455,7 @@ match pattern_match_class:
# trailing # trailing
# trailing # trailing
): ):
... pass
case A( case A(
b # b b # b
@ -487,26 +487,26 @@ match pattern_match_or:
# own line 4 # own line 4
c # trailing 5 c # trailing 5
): ):
... pass
case ( case (
(a) (a)
| # trailing | # trailing
( b ) ( b )
): ):
... pass
case (a|b|c): case (a|b|c):
... pass
case foo | bar | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh: case foo | bar | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh:
... pass
case ( # end of line case ( # end of line
a | b a | b
# own line # own line
): ):
... pass
# Single-element tuples. # Single-element tuples.
@ -770,9 +770,9 @@ match pattern_singleton:
): ):
pass pass
case True: # trailing case True: # trailing
... pass
case False: case False:
... pass
match foo: match foo:
@ -996,26 +996,26 @@ match pattern_match_class:
case Point2D( case Point2D(
# own line # own line
): ):
... pass
case ( case (
Point2D Point2D
# own line # own line
() ()
): ):
... pass
case Point2D( # end of line line case Point2D( # end of line line
): ):
... pass
case Point2D( # end of line case Point2D( # end of line
0, 0 0, 0
): ):
... pass
case Point2D(0, 0): case Point2D(0, 0):
... pass
case Point2D( case Point2D(
( # end of line ( # end of line
@ -1024,17 +1024,17 @@ match pattern_match_class:
), ),
0, 0,
): ):
... pass
case Point3D( case Point3D(
x=0, x=0,
y=0, y=0,
z=000000000000000000000000000000000000000000000000000000000000000000000000000000000, z=000000000000000000000000000000000000000000000000000000000000000000000000000000000,
): ):
... pass
case Bar(0, a=None, b="hello"): case Bar(0, a=None, b="hello"):
... pass
case FooBar( # leading case FooBar( # leading
# leading # leading
@ -1045,7 +1045,7 @@ match pattern_match_class:
# trailing # trailing
# trailing # trailing
): ):
... pass
case A( case A(
# b # b
@ -1075,7 +1075,7 @@ match pattern_match_or:
# own line 4 # own line 4
| c # trailing 5 | c # trailing 5
): ):
... pass
case ( case (
( (
@ -1083,24 +1083,24 @@ match pattern_match_or:
) )
| (b) | (b)
): ):
... pass
case a | b | c: case a | b | c:
... pass
case ( case (
foo foo
| bar | bar
| aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh | aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaahhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhhh
): ):
... pass
case ( # end of line case ( # end of line
a a
| b | b
# own line # own line
): ):
... pass
# Single-element tuples. # Single-element tuples.

View File

@ -5,74 +5,74 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/
## Input ## Input
```py ```py
try: try:
... pass
except: except:
... pass
try: try:
... pass
except (KeyError): # should remove brackets and be a single line except (KeyError): # should remove brackets and be a single line
... pass
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except (Exception, ValueError) as exc: # except line except (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except KeyError as key: # except line 2 except KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# with line breaks # with line breaks
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except (Exception, ValueError) as exc: # except line except (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except KeyError as key: # except line 2 except KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# with line breaks # with line breaks
try: try:
... pass
except: except:
... pass
try: try:
... pass
except (Exception, Exception, Exception, Exception, Exception, Exception, Exception) as exc: # splits exception over multiple lines except (Exception, Exception, Exception, Exception, Exception, Exception, Exception) as exc: # splits exception over multiple lines
... pass
try: try:
... pass
except: except:
a = 10 # trailing comment1 a = 10 # trailing comment1
b = 11 # trailing comment2 b = 11 # trailing comment2
@ -80,21 +80,21 @@ except:
# try/except*, mostly the same as try # try/except*, mostly the same as try
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except* (Exception, ValueError) as exc: # except line except* (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except* KeyError as key: # except line 2 except* KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# try and try star are statements with body # try and try star are statements with body
# Minimized from https://github.com/python/cpython/blob/99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1/Lib/getpass.py#L68-L91 # Minimized from https://github.com/python/cpython/blob/99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1/Lib/getpass.py#L68-L91
@ -177,67 +177,67 @@ finally:
## Output ## Output
```py ```py
try: try:
... pass
except: except:
... pass
try: try:
... pass
except KeyError: # should remove brackets and be a single line except KeyError: # should remove brackets and be a single line
... pass
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except (Exception, ValueError) as exc: # except line except (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except KeyError as key: # except line 2 except KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# with line breaks # with line breaks
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except (Exception, ValueError) as exc: # except line except (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except KeyError as key: # except line 2 except KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# with line breaks # with line breaks
try: try:
... pass
except: except:
... pass
try: try:
... pass
except ( except (
Exception, Exception,
Exception, Exception,
@ -247,11 +247,11 @@ except (
Exception, Exception,
Exception, Exception,
) as exc: # splits exception over multiple lines ) as exc: # splits exception over multiple lines
... pass
try: try:
... pass
except: except:
a = 10 # trailing comment1 a = 10 # trailing comment1
b = 11 # trailing comment2 b = 11 # trailing comment2
@ -259,21 +259,21 @@ except:
# try/except*, mostly the same as try # try/except*, mostly the same as try
try: # try try: # try
... pass
# end of body # end of body
# before except # before except
except* (Exception, ValueError) as exc: # except line except* (Exception, ValueError) as exc: # except line
... pass
# before except 2 # before except 2
except* KeyError as key: # except line 2 except* KeyError as key: # except line 2
... pass
# in body 2 # in body 2
# before else # before else
else: else:
... pass
# before finally # before finally
finally: finally:
... pass
# try and try star are statements with body # try and try star are statements with body
# Minimized from https://github.com/python/cpython/blob/99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1/Lib/getpass.py#L68-L91 # Minimized from https://github.com/python/cpython/blob/99b00efd5edfd5b26bf9e2a35cbfc96277fdcbb1/Lib/getpass.py#L68-L91

View File

@ -21,7 +21,7 @@ while aVeryLongConditionThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGo
pass pass
else: else:
... pass
while ( while (
some_condition(unformatted, args) and anotherCondition or aThirdCondition some_condition(unformatted, args) and anotherCondition or aThirdCondition
@ -55,7 +55,7 @@ while aVeryLongConditionThatSpillsOverToTheNextLineBecauseItIsExtremelyLongAndGo
pass pass
else: else:
... pass
while ( while (
some_condition(unformatted, args) and anotherCondition or aThirdCondition some_condition(unformatted, args) and anotherCondition or aThirdCondition

View File

@ -5,18 +5,18 @@ input_file: crates/ruff_python_formatter/resources/test/fixtures/ruff/statement/
## Input ## Input
```py ```py
with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
# trailing # trailing
with a, a: # after colon with a, a: # after colon
... pass
# trailing # trailing
with ( with (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
): ):
... pass
# trailing # trailing
@ -25,7 +25,7 @@ with (
, # comma , # comma
b # c b # c
): # colon ): # colon
... pass
with ( with (
@ -36,7 +36,7 @@ with (
, # comma , # comma
c # c c # c
): # colon ): # colon
... # body pass # body
# body trailing own # body trailing own
with ( with (
@ -48,14 +48,14 @@ with (
with (a,): # magic trailing comma with (a,): # magic trailing comma
... pass
with (a): # should remove brackets with (a): # should remove brackets
... pass
with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as c: with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as c:
... pass
# currently unparsable by black: https://github.com/psf/black/issues/3678 # currently unparsable by black: https://github.com/psf/black/issues/3678
@ -66,45 +66,45 @@ with (a, *b):
with ( with (
# leading comment # leading comment
a) as b: ... a) as b: pass
with ( with (
# leading comment # leading comment
a as b a as b
): ... ): pass
with ( with (
a as b a as b
# trailing comment # trailing comment
): ... ): pass
with ( with (
a as ( a as (
# leading comment # leading comment
b b
) )
): ... ): pass
with ( with (
a as ( a as (
b b
# trailing comment # trailing comment
) )
): ... ): pass
with (a # trailing same line comment with (a # trailing same line comment
# trailing own line comment # trailing own line comment
) as b: ... ) as b: pass
with ( with (
a # trailing same line comment a # trailing same line comment
# trailing own line comment # trailing own line comment
as b as b
): ... ): pass
with (a # trailing same line comment with (a # trailing same line comment
# trailing own line comment # trailing own line comment
) as b: ... ) as b: pass
with ( with (
(a (a
@ -112,7 +112,7 @@ with (
) )
as # trailing as same line comment as # trailing as same line comment
b # trailing b same line comment b # trailing b same line comment
): ... ): pass
with ( with (
# comment # comment
@ -163,7 +163,7 @@ with (
CtxManager2() as example2, CtxManager2() as example2,
CtxManager2() as example2, CtxManager2() as example2,
): ):
... pass
with [ with [
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@ -171,7 +171,7 @@ with [
"cccccccccccccccccccccccccccccccccccccccccc", "cccccccccccccccccccccccccccccccccccccccccc",
dddddddddddddddddddddddddddddddd, dddddddddddddddddddddddddddddddd,
] as example1, aaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccccccc + ddddddddddddddddd as example2, CtxManager222222222222222() as example2: ] as example1, aaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccccccc + ddddddddddddddddd as example2, CtxManager222222222222222() as example2:
... pass
# Comments on open parentheses # Comments on open parentheses
with ( # comment with ( # comment
@ -179,7 +179,7 @@ with ( # comment
CtxManager2() as example2, CtxManager2() as example2,
CtxManager3() as example3, CtxManager3() as example3,
): ):
... pass
with ( # outer comment with ( # outer comment
( # inner comment ( # inner comment
@ -188,25 +188,25 @@ with ( # outer comment
CtxManager2() as example2, CtxManager2() as example2,
CtxManager3() as example3, CtxManager3() as example3,
): ):
... pass
with ( # outer comment with ( # outer comment
CtxManager() CtxManager()
) as example: ) as example:
... pass
with ( # outer comment with ( # outer comment
CtxManager() CtxManager()
) as example, ( # inner comment ) as example, ( # inner comment
CtxManager2() CtxManager2()
) as example2: ) as example2:
... pass
with ( # outer comment with ( # outer comment
CtxManager1(), CtxManager1(),
CtxManager2(), CtxManager2(),
) as example: ) as example:
... pass
with ( # outer comment with ( # outer comment
( # inner comment ( # inner comment
@ -214,7 +214,7 @@ with ( # outer comment
), ),
CtxManager2(), CtxManager2(),
) as example: ) as example:
... pass
# Breaking of with items. # Breaking of with items.
with (test # bar with (test # bar
@ -318,18 +318,18 @@ if True:
## Output ## Output
```py ```py
with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa: with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa:
... pass
# trailing # trailing
with a, a: # after colon with a, a: # after colon
... pass
# trailing # trailing
with ( with (
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa, aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa,
): ):
... pass
# trailing # trailing
@ -337,7 +337,7 @@ with (
a, # a # comma a, # a # comma
b, # c b, # c
): # colon ): # colon
... pass
with ( with (
@ -347,7 +347,7 @@ with (
), # b # comma ), # b # comma
c, # c c, # c
): # colon ): # colon
... # body pass # body
# body trailing own # body trailing own
with ( with (
@ -362,14 +362,14 @@ with (
with ( with (
a, a,
): # magic trailing comma ): # magic trailing comma
... pass
with a: # should remove brackets with a: # should remove brackets
... pass
with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as c: with aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa + bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb as c:
... pass
# currently unparsable by black: https://github.com/psf/black/issues/3678 # currently unparsable by black: https://github.com/psf/black/issues/3678
@ -382,49 +382,49 @@ with (
# leading comment # leading comment
a a
) as b: ) as b:
... pass
with ( with (
# leading comment # leading comment
a as b a as b
): ):
... pass
with ( with (
a as b a as b
# trailing comment # trailing comment
): ):
... pass
with a as ( with a as (
# leading comment # leading comment
b b
): ):
... pass
with a as ( with a as (
b b
# trailing comment # trailing comment
): ):
... pass
with ( with (
a # trailing same line comment a # trailing same line comment
# trailing own line comment # trailing own line comment
) as b: ) as b:
... pass
with ( with (
a # trailing same line comment a # trailing same line comment
# trailing own line comment # trailing own line comment
) as b: ) as b:
... pass
with ( with (
a # trailing same line comment a # trailing same line comment
# trailing own line comment # trailing own line comment
) as b: ) as b:
... pass
with ( with (
( (
@ -434,7 +434,7 @@ with (
b b
) # trailing b same line comment ) # trailing b same line comment
): ):
... pass
with ( with (
# comment # comment
@ -485,7 +485,7 @@ with (
CtxManager2() as example2, CtxManager2() as example2,
CtxManager2() as example2, CtxManager2() as example2,
): ):
... pass
with [ with [
"aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa",
@ -493,7 +493,7 @@ with [
"cccccccccccccccccccccccccccccccccccccccccc", "cccccccccccccccccccccccccccccccccccccccccc",
dddddddddddddddddddddddddddddddd, dddddddddddddddddddddddddddddddd,
] as example1, aaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccccccc + ddddddddddddddddd as example2, CtxManager222222222222222() as example2: ] as example1, aaaaaaaaaaaaaaaaaaaaaaaaaa * bbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb * cccccccccccccccccccccccccccc + ddddddddddddddddd as example2, CtxManager222222222222222() as example2:
... pass
# Comments on open parentheses # Comments on open parentheses
with ( # comment with ( # comment
@ -501,7 +501,7 @@ with ( # comment
CtxManager2() as example2, CtxManager2() as example2,
CtxManager3() as example3, CtxManager3() as example3,
): ):
... pass
with ( # outer comment with ( # outer comment
( # inner comment ( # inner comment
@ -510,25 +510,25 @@ with ( # outer comment
CtxManager2() as example2, CtxManager2() as example2,
CtxManager3() as example3, CtxManager3() as example3,
): ):
... pass
with ( # outer comment with ( # outer comment
CtxManager() CtxManager()
) as example: ) as example:
... pass
with ( # outer comment with ( # outer comment
CtxManager() CtxManager()
) as example, ( # inner comment ) as example, ( # inner comment
CtxManager2() CtxManager2()
) as example2: ) as example2:
... pass
with ( # outer comment with ( # outer comment
CtxManager1(), CtxManager1(),
CtxManager2(), CtxManager2(),
) as example: ) as example:
... pass
with ( # outer comment with ( # outer comment
( # inner comment ( # inner comment
@ -536,7 +536,7 @@ with ( # outer comment
), ),
CtxManager2(), CtxManager2(),
) as example: ) as example:
... pass
# Breaking of with items. # Breaking of with items.
with test as ( # bar # foo with test as ( # bar # foo

View File

@ -23,7 +23,7 @@ class Test:
c = 30 c = 30
while a == 10: while a == 10:
... print(a)
# trailing comment with one line before # trailing comment with one line before
@ -32,7 +32,7 @@ while a == 10:
d = 40 d = 40
while b == 20: while b == 20:
... print(b)
# no empty line before # no empty line before
e = 50 # one empty line before e = 50 # one empty line before
@ -61,7 +61,7 @@ class Test:
c = 30 c = 30
while a == 10: while a == 10:
... print(a)
# trailing comment with one line before # trailing comment with one line before
@ -70,7 +70,7 @@ while a == 10:
d = 40 d = 40
while b == 20: while b == 20:
... print(b)
# no empty line before # no empty line before
e = 50 # one empty line before e = 50 # one empty line before