-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Format symmetric list concatenations in preview #5259
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
ColumbusLabs
wants to merge
5
commits into
psf:main
Choose a base branch
from
ColumbusLabs:codex/black-260-symmetric-list-concat
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
48e1947
Format symmetric list concatenations in preview
ColumbusLabs 678485f
Preserve multiline list concatenation formatting
ColumbusLabs 79a44ca
Clarify symmetric list concatenation scope
ColumbusLabs 12b570b
fix: refine symmetric list concatenation preview
ColumbusLabs 339735b
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
This file contains hidden or 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
138 changes: 138 additions & 0 deletions
138
tests/data/cases/preview_symmetric_list_concatenation.py
This file contains hidden or 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,138 @@ | ||
| # flags: --preview | ||
|
|
||
| # Regression test for https://github.com/psf/black/issues/260. | ||
| search_fields = (["file__%s" % field for field in FileAdmin.search_fields] + ["resource__%s" % field for field in ResourceAdmin.search_fields]) | ||
|
|
||
| # Plain list displays receive the same symmetric treatment. | ||
| names = ["Alice", "Bob", "Charlie", "Diana", "Edward"] + ["Fiona", "George", "Harriet", "Isabelle"] | ||
|
|
||
| # Comments on an operand stay attached and formatting remains stable. | ||
| commented = ( | ||
| ["first_long_value", "second_long_value", "third_long_value"] # first list | ||
| + ["fourth_long_value", "fifth_long_value", "sixth_long_value"] | ||
| ) | ||
|
|
||
| commented_left = ( | ||
| ["first_value", "second_value", "third_value"] # abc | ||
| + ["fourth_value", "fifth_value", "sixth_value"] | ||
| ) | ||
| commented_right = ( | ||
| ["first_value", "second_value", "third_value"] | ||
| + ["fourth_value", "fifth_value", "sixth_value"] # abc | ||
| ) | ||
|
|
||
| # Split symmetrically even when the RHS alone fits inside optional parentheses. | ||
| values = [first_value, second_value, third_value] + [fourth_value, fifth_value, sixth_value] | ||
|
|
||
| # Chained concatenations already use the normal delimiter split. | ||
| chained = ["first_long_value", "second_long_value"] + ["third_long_value", "fourth_long_value"] + ["fifth_long_value", "sixth_long_value"] | ||
|
|
||
| # Mixed operands are not symmetric list concatenations. | ||
| mixed_left = ["first_long_value", "second_long_value", "third_long_value"] + tuple_with_a_very_long_name | ||
| mixed_right = list_with_a_very_long_name + ["first_long_value", "second_long_value", "third_long_value"] | ||
|
|
||
| # Short concatenations stay on one line. | ||
| small = [1, 2] + [3, 4] | ||
|
|
||
| # Lists that already require bracket splitting keep the existing formatting. | ||
| long_left = ["first_value_with_an_extremely_long_name", "second_value_with_an_extremely_long_name", "third"] + ["short"] | ||
| long_right = ["short"] + ["first_value_with_an_extremely_long_name", "second_value_with_an_extremely_long_name", "third"] | ||
| both_long = ["first_value_with_an_extremely_long_name", "second_value_with_an_extremely_long_name", "third"] + ["fourth_value_with_an_extremely_long_name", "fifth_value_with_an_extremely_long_name", "sixth"] | ||
|
|
||
| # Magic trailing commas also keep the existing formatting. | ||
| magic_left = [ | ||
| "first_long_value", | ||
| "second_long_value", | ||
| ] + ["third_long_value", "fourth_long_value"] | ||
| magic_right = ["first_long_value", "second_long_value"] + [ | ||
| "third_long_value", | ||
| "fourth_long_value", | ||
| ] | ||
|
|
||
| # output | ||
|
|
||
| # Regression test for https://github.com/psf/black/issues/260. | ||
| search_fields = ( | ||
| ["file__%s" % field for field in FileAdmin.search_fields] | ||
| + ["resource__%s" % field for field in ResourceAdmin.search_fields] | ||
| ) | ||
|
|
||
| # Plain list displays receive the same symmetric treatment. | ||
| names = ( | ||
| ["Alice", "Bob", "Charlie", "Diana", "Edward"] | ||
| + ["Fiona", "George", "Harriet", "Isabelle"] | ||
| ) | ||
|
|
||
| # Comments on an operand stay attached and formatting remains stable. | ||
| commented = ( | ||
| ["first_long_value", "second_long_value", "third_long_value"] # first list | ||
| + ["fourth_long_value", "fifth_long_value", "sixth_long_value"] | ||
| ) | ||
|
|
||
| commented_left = ( | ||
| ["first_value", "second_value", "third_value"] # abc | ||
| + ["fourth_value", "fifth_value", "sixth_value"] | ||
| ) | ||
| commented_right = ( | ||
| ["first_value", "second_value", "third_value"] | ||
| + ["fourth_value", "fifth_value", "sixth_value"] # abc | ||
| ) | ||
|
|
||
| # Split symmetrically even when the RHS alone fits inside optional parentheses. | ||
| values = ( | ||
| [first_value, second_value, third_value] | ||
| + [fourth_value, fifth_value, sixth_value] | ||
| ) | ||
|
|
||
| # Chained concatenations already use the normal delimiter split. | ||
| chained = ( | ||
| ["first_long_value", "second_long_value"] | ||
| + ["third_long_value", "fourth_long_value"] | ||
| + ["fifth_long_value", "sixth_long_value"] | ||
| ) | ||
|
|
||
| # Mixed operands are not symmetric list concatenations. | ||
| mixed_left = [ | ||
| "first_long_value", | ||
| "second_long_value", | ||
| "third_long_value", | ||
| ] + tuple_with_a_very_long_name | ||
| mixed_right = list_with_a_very_long_name + [ | ||
| "first_long_value", | ||
| "second_long_value", | ||
| "third_long_value", | ||
| ] | ||
|
|
||
| # Short concatenations stay on one line. | ||
| small = [1, 2] + [3, 4] | ||
|
|
||
| # Lists that already require bracket splitting keep the existing formatting. | ||
| long_left = [ | ||
| "first_value_with_an_extremely_long_name", | ||
| "second_value_with_an_extremely_long_name", | ||
| "third", | ||
| ] + ["short"] | ||
| long_right = ["short"] + [ | ||
| "first_value_with_an_extremely_long_name", | ||
| "second_value_with_an_extremely_long_name", | ||
| "third", | ||
| ] | ||
| both_long = [ | ||
| "first_value_with_an_extremely_long_name", | ||
| "second_value_with_an_extremely_long_name", | ||
| "third", | ||
| ] + [ | ||
| "fourth_value_with_an_extremely_long_name", | ||
| "fifth_value_with_an_extremely_long_name", | ||
| "sixth", | ||
| ] | ||
|
|
||
| # Magic trailing commas also keep the existing formatting. | ||
| magic_left = [ | ||
| "first_long_value", | ||
| "second_long_value", | ||
| ] + ["third_long_value", "fourth_long_value"] | ||
| magic_right = ["first_long_value", "second_long_value"] + [ | ||
| "third_long_value", | ||
| "fourth_long_value", | ||
| ] |
12 changes: 12 additions & 0 deletions
12
tests/data/cases/preview_symmetric_list_concatenation_line_length.py
This file contains hidden or 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,12 @@ | ||
| # flags: --preview --line-length=60 | ||
|
|
||
| values = [first_value, second_value] + [third_value, fourth_value] | ||
| short_values = [first_value] + [second_value] | ||
|
|
||
| # output | ||
|
|
||
| values = ( | ||
| [first_value, second_value] | ||
| + [third_value, fourth_value] | ||
| ) | ||
| short_values = [first_value] + [second_value] |
15 changes: 15 additions & 0 deletions
15
tests/data/cases/preview_symmetric_list_concatenation_skip_magic.py
This file contains hidden or 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,15 @@ | ||
| # flags: --preview --skip-magic-trailing-comma | ||
|
|
||
| # Ignored trailing commas do not prevent symmetric formatting. | ||
| values = [ | ||
| "first_long_value", | ||
| "second_long_value", | ||
| ] + ["third_long_value", "fourth_long_value"] | ||
|
|
||
| # output | ||
|
|
||
| # Ignored trailing commas do not prevent symmetric formatting. | ||
| values = ( | ||
| ["first_long_value", "second_long_value"] | ||
| + ["third_long_value", "fourth_long_value"] | ||
| ) |
This file contains hidden or 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,4 @@ | ||
| # Stable style must keep the existing asymmetric bracket split. | ||
| search_fields = ["file__%s" % field for field in FileAdmin.search_fields] + [ | ||
| "resource__%s" % field for field in ResourceAdmin.search_fields | ||
| ] |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.