mirror of
https://github.com/astral-sh/ruff.git
synced 2025-09-26 11:59:10 +00:00
Format ExprTuple (#4963)
This implements formatting ExprTuple, including magic trailing comma. I intentionally didn't change the settings mechanism but just added a dummy global const flag. Besides the snapshots, I added custom breaking/joining tests and a deeply nested test case. The diffs look better than previously, proper black compatibility depends on parentheses handling. --------- Co-authored-by: Micha Reiser <micha@reiser.io>
This commit is contained in:
parent
8161757229
commit
e586c27590
25 changed files with 735 additions and 219 deletions
59
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/tuple_expression.py
vendored
Normal file
59
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/tuple_expression.py
vendored
Normal file
|
@ -0,0 +1,59 @@
|
|||
# Non-wrapping parentheses checks
|
||||
a1 = 1, 2
|
||||
a2 = (1, 2)
|
||||
a3 = (1, 2), 3
|
||||
a4 = ((1, 2), 3)
|
||||
|
||||
# Wrapping parentheses checks
|
||||
b1 = (("Michael", "Ende"), ("Der", "satanarchäolügenialkohöllische", "Wunschpunsch"), ("Beelzebub", "Irrwitzer"), ("Tyrannja", "Vamperl"),)
|
||||
b2 = ("akjdshflkjahdslkfjlasfdahjlfds", "ljklsadhflakfdajflahfdlajfhafldkjalfj", "ljklsadhflakfdajflahfdlajfhafldkjalf2",)
|
||||
b3 = ("The", "Night", "of", "Wishes:", "Or", "the", "Satanarchaeolidealcohellish", "Notion", "Potion",)
|
||||
|
||||
# Nested wrapping parentheses check
|
||||
c1 = (("cicero"), ("Qui", "autem,", "si", "maxime", "hoc", "placeat,", "moderatius", "tamen", "id", "uolunt", "fieri,", "difficilem", "quandam", "temperantiam", "postulant", "in", "eo,", "quod", "semel", "admissum", "coerceri", "reprimique", "non", "potest,", "ut", "propemodum", "iustioribus", "utamur", "illis,", "qui", "omnino", "auocent", "a", "philosophia,", "quam", "his,", "qui", "rebus", "infinitis", "modum", "constituant", "in", "reque", "eo", "meliore,", "quo", "maior", "sit,", "mediocritatem", "desiderent."), ("de", "finibus", "bonorum", "et", "malorum"))
|
||||
|
||||
# Deeply nested parentheses
|
||||
d1 = ((("3D",),),)
|
||||
d2 = (((((((((((((((((((((((((((("¯\_(ツ)_/¯",),),),),),),),),),),),),),),),),),),),),),),),),),),),)
|
||||
|
||||
# Join and magic trailing comma
|
||||
e1 = (
|
||||
1,
|
||||
2
|
||||
)
|
||||
e2 = (
|
||||
1,
|
||||
2,
|
||||
)
|
||||
e3 = (
|
||||
1,
|
||||
)
|
||||
e4 = (
|
||||
"Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor",
|
||||
"incididunt"
|
||||
)
|
||||
|
||||
# Empty tuples and comments
|
||||
f1 = (
|
||||
# empty
|
||||
)
|
||||
f2 = ()
|
||||
|
||||
# Comments in other tuples
|
||||
g1 = ( # a
|
||||
# b
|
||||
1, # c
|
||||
# d
|
||||
) # e
|
||||
g2 = ( # a
|
||||
# b
|
||||
1, # c
|
||||
# d
|
||||
2, # e
|
||||
# f
|
||||
) # g
|
||||
|
||||
# Ensure the correct number of parentheses
|
||||
h1 = ((((1, 2))))
|
||||
h2 = ((((1, "qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurpqurpqurpqurpqurpqurüqurqpuriq"))))
|
||||
h3 = 1, "qweiurpoiqwurepqiurpqirpuqoiwrupqoirupqoirupqoiurpqiorupwqiourpqurpqurpqurpqurpqurpqurüqurqpuriq"
|
Loading…
Add table
Add a link
Reference in a new issue