-
Notifications
You must be signed in to change notification settings - Fork 1.2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement multiline dictionary and list indentation
- Loading branch information
1 parent
9f5102d
commit 73183f0
Showing
10 changed files
with
1,480 additions
and
8 deletions.
There are no files selected for viewing
3 changes: 3 additions & 0 deletions
3
...xtures/black/simple_cases/preview_hug_parens_with_braces_and_square_brackets.options.json
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,3 @@ | ||
{ | ||
"preview": "enabled" | ||
} |
141 changes: 141 additions & 0 deletions
141
...es/test/fixtures/black/simple_cases/preview_hug_parens_with_braces_and_square_brackets.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,141 @@ | ||
def foo_brackets(request): | ||
return JsonResponse( | ||
{ | ||
"var_1": foo, | ||
"var_2": bar, | ||
} | ||
) | ||
|
||
def foo_square_brackets(request): | ||
return JsonResponse( | ||
[ | ||
"var_1", | ||
"var_2", | ||
] | ||
) | ||
|
||
func({"a": 37, "b": 42, "c": 927, "aaaaaaaaaaaaaaaaaaaaaaaaa": 11111111111111111111111111111111111111111}) | ||
|
||
func(["random_string_number_one","random_string_number_two","random_string_number_three","random_string_number_four"]) | ||
|
||
func( | ||
{ | ||
# expand me | ||
'a':37, | ||
'b':42, | ||
'c':927 | ||
} | ||
) | ||
|
||
func( | ||
[ | ||
'a', | ||
'b', | ||
'c', | ||
] | ||
) | ||
|
||
func( | ||
[ | ||
'a', | ||
'b', | ||
'c', | ||
], | ||
) | ||
|
||
func( # a | ||
[ # b | ||
"c", # c | ||
"d", # d | ||
"e", # e | ||
] # f | ||
) # g | ||
|
||
func( # a | ||
{ # b | ||
"c": 1, # c | ||
"d": 2, # d | ||
"e": 3, # e | ||
} # f | ||
) # g | ||
|
||
func( | ||
# preserve me | ||
[ | ||
"c", | ||
"d", | ||
"e", | ||
] | ||
) | ||
|
||
func( | ||
[ # preserve me but hug brackets | ||
"c", | ||
"d", | ||
"e", | ||
] | ||
) | ||
|
||
func( | ||
[ | ||
# preserve me but hug brackets | ||
"c", | ||
"d", | ||
"e", | ||
] | ||
) | ||
|
||
func( | ||
[ | ||
"c", | ||
# preserve me but hug brackets | ||
"d", | ||
"e", | ||
] | ||
) | ||
|
||
func( | ||
[ | ||
"c", | ||
"d", | ||
"e", | ||
# preserve me but hug brackets | ||
] | ||
) | ||
|
||
func( | ||
[ | ||
"c", | ||
"d", | ||
"e", | ||
] # preserve me but hug brackets | ||
) | ||
|
||
func( | ||
[ | ||
"c", | ||
"d", | ||
"e", | ||
] | ||
# preserve me | ||
) | ||
|
||
func([x for x in "short line"]) | ||
func([x for x in "long line long line long line long line long line long line long line"]) | ||
func([x for x in [x for x in "long line long line long line long line long line long line long line"]]) | ||
|
||
func({"short line"}) | ||
func({"long line", "long long line", "long long long line", "long long long long line", "long long long long long line"}) | ||
func({{"long line", "long long line", "long long long line", "long long long long line", "long long long long long line"}}) | ||
|
||
foooooooooooooooooooo( | ||
[{c: n + 1 for c in range(256)} for n in range(100)] + [{}], {size} | ||
) | ||
|
||
baaaaaaaaaaaaar( | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], {x}, "a string", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
) | ||
|
||
foo(*["long long long long long line", "long long long long long line", "long long long long long line"]) | ||
|
||
foo(*[str(i) for i in range(100000000000000000000000000000000000000000000000000000000000)]) |
159 changes: 159 additions & 0 deletions
159
.../fixtures/black/simple_cases/preview_hug_parens_with_braces_and_square_brackets.py.expect
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,159 @@ | ||
def foo_brackets(request): | ||
return JsonResponse({ | ||
"var_1": foo, | ||
"var_2": bar, | ||
}) | ||
|
||
|
||
def foo_square_brackets(request): | ||
return JsonResponse([ | ||
"var_1", | ||
"var_2", | ||
]) | ||
|
||
|
||
func({ | ||
"a": 37, | ||
"b": 42, | ||
"c": 927, | ||
"aaaaaaaaaaaaaaaaaaaaaaaaa": 11111111111111111111111111111111111111111, | ||
}) | ||
|
||
func([ | ||
"random_string_number_one", | ||
"random_string_number_two", | ||
"random_string_number_three", | ||
"random_string_number_four", | ||
]) | ||
|
||
func({ | ||
# expand me | ||
"a": 37, | ||
"b": 42, | ||
"c": 927, | ||
}) | ||
|
||
func([ | ||
"a", | ||
"b", | ||
"c", | ||
]) | ||
|
||
func( | ||
[ | ||
"a", | ||
"b", | ||
"c", | ||
], | ||
) | ||
|
||
func([ # a # b | ||
"c", # c | ||
"d", # d | ||
"e", # e | ||
]) # f # g | ||
|
||
func({ # a # b | ||
"c": 1, # c | ||
"d": 2, # d | ||
"e": 3, # e | ||
}) # f # g | ||
|
||
func( | ||
# preserve me | ||
[ | ||
"c", | ||
"d", | ||
"e", | ||
] | ||
) | ||
|
||
func([ # preserve me but hug brackets | ||
"c", | ||
"d", | ||
"e", | ||
]) | ||
|
||
func([ | ||
# preserve me but hug brackets | ||
"c", | ||
"d", | ||
"e", | ||
]) | ||
|
||
func([ | ||
"c", | ||
# preserve me but hug brackets | ||
"d", | ||
"e", | ||
]) | ||
|
||
func([ | ||
"c", | ||
"d", | ||
"e", | ||
# preserve me but hug brackets | ||
]) | ||
|
||
func([ | ||
"c", | ||
"d", | ||
"e", | ||
]) # preserve me but hug brackets | ||
|
||
func( | ||
[ | ||
"c", | ||
"d", | ||
"e", | ||
] | ||
# preserve me | ||
) | ||
|
||
func([x for x in "short line"]) | ||
func([ | ||
x for x in "long line long line long line long line long line long line long line" | ||
]) | ||
func([ | ||
x | ||
for x in [ | ||
x | ||
for x in "long line long line long line long line long line long line long line" | ||
] | ||
]) | ||
|
||
func({"short line"}) | ||
func({ | ||
"long line", | ||
"long long line", | ||
"long long long line", | ||
"long long long long line", | ||
"long long long long long line", | ||
}) | ||
func({ | ||
{ | ||
"long line", | ||
"long long line", | ||
"long long long line", | ||
"long long long long line", | ||
"long long long long long line", | ||
} | ||
}) | ||
|
||
foooooooooooooooooooo( | ||
[{c: n + 1 for c in range(256)} for n in range(100)] + [{}], {size} | ||
) | ||
|
||
baaaaaaaaaaaaar( | ||
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10], {x}, "a string", [1, 2, 3, 4, 5, 6, 7, 8, 9, 10] | ||
) | ||
|
||
foo(*[ | ||
"long long long long long line", | ||
"long long long long long line", | ||
"long long long long long line", | ||
]) | ||
|
||
foo(*[ | ||
str(i) for i in range(100000000000000000000000000000000000000000000000000000000000) | ||
]) |
69 changes: 69 additions & 0 deletions
69
crates/ruff_python_formatter/resources/test/fixtures/ruff/expression/hug.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,69 @@ | ||
# Preview style: hug brackets to call parentheses. | ||
func([1, 2, 3,]) | ||
|
||
func( # comment | ||
[1, 2, 3,]) | ||
|
||
func( | ||
# comment | ||
[1, 2, 3,]) | ||
|
||
func([1, 2, 3,] # comment | ||
) | ||
|
||
func([1, 2, 3,] | ||
# comment | ||
) | ||
|
||
func([ # comment | ||
1, 2, 3,] | ||
) | ||
|
||
func(([1, 2, 3,])) | ||
|
||
# Ensure that comprehensions hug too. | ||
func([(x, y,) for (x, y) in z]) | ||
|
||
# Ensure that dictionaries hug too. | ||
func({1: 2, 3: 4, 5: 6,}) | ||
|
||
# Ensure that the same behavior is applied to parenthesized expressions. | ||
([1, 2, 3,]) | ||
|
||
( # comment | ||
[1, 2, 3,]) | ||
|
||
( | ||
[ # comment | ||
1, 2, 3,]) | ||
|
||
# Ensure that starred arguments are also hugged. | ||
foo( | ||
*[ | ||
a_long_function_name(a_long_variable_name) | ||
for a_long_variable_name in some_generator | ||
] | ||
) | ||
|
||
foo( | ||
* # comment | ||
[ | ||
a_long_function_name(a_long_variable_name) | ||
for a_long_variable_name in some_generator | ||
] | ||
) | ||
|
||
foo( | ||
**[ | ||
a_long_function_name(a_long_variable_name) | ||
for a_long_variable_name in some_generator | ||
] | ||
) | ||
|
||
foo( | ||
** # comment | ||
[ | ||
a_long_function_name(a_long_variable_name) | ||
for a_long_variable_name in some_generator | ||
] | ||
) |
Oops, something went wrong.