-
Notifications
You must be signed in to change notification settings - Fork 2.5k
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
fix: Remove parenthesis around sole list items #4312
Open
cobaltt7
wants to merge
16
commits into
psf:main
Choose a base branch
from
cobaltt7:gh-3545
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
16 commits
Select commit
Hold shift + click to select a range
183a65b
fix: Remove parenthesis around sole list items
cobaltt7 ad570d2
Merge branch 'main' of https://github.com/psf/black into gh-3545
cobaltt7 e8d291d
fix: Remove parenthesis around sole list items
cobaltt7 fd49184
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 40140e4
Discard changes to src/black/lines.py
cobaltt7 5ceaf93
Add docs and tests for the simple cases lol
cobaltt7 cbf5730
Merge branch 'main' into gh-3545
JelleZijlstra bdb0a8a
Split into multiple features
cobaltt7 a7c9f5b
regen schema
cobaltt7 8c4519f
Merge branch 'main' into gh-3545
cobaltt7 85175cd
Merge branch 'main' into gh-3545
cobaltt7 a8515e3
Update future_style.md
cobaltt7 ee65f5a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] 6937902
Remove from unstable style
cobaltt7 d2cad58
Merge branch 'main' into gh-3545
cobaltt7 602599e
Merge branch 'main' into gh-3545
cobaltt7 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 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 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 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 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 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
156 changes: 156 additions & 0 deletions
156
tests/data/cases/preview_remove_lone_list_item_parens.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,156 @@ | ||
# flags: --unstable | ||
items = [(123)] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Add a test containing a generator expression, to make sure we don't turn it into a listcomp:
Also add tests with comments in various places (e.g., after the opening paren, before the closing paren). Such cases tend to expose bugs in Black. |
||
items = [(True)] | ||
items = [(((((True)))))] | ||
items = [(((((True,)))))] | ||
items = [((((()))))] | ||
|
||
items = [ | ||
( | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
if some_var == "long strings" | ||
else {"key": "val"} | ||
) | ||
] | ||
items = [ | ||
( | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
if some_var == "long strings" | ||
else {"key": "val"} | ||
), | ||
] | ||
items = [ | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
if some_var == "long strings" | ||
else {"key": "val"} | ||
] | ||
items = [ | ||
( | ||
{"key1": "val1", "key2": "val2"} | ||
if some_var == "" | ||
else {"key": "val"} | ||
) | ||
] | ||
items = [{"key1": "val1", "key2": "val2"} if some_var == "" else {"key": "val"}] | ||
items = [ | ||
( | ||
"123456890123457890123468901234567890" | ||
if some_var == "long strings" | ||
else "123467890123467890" | ||
) | ||
] | ||
|
||
items = [ | ||
( | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
and some_var == "long strings" | ||
and {"key": "val"} | ||
) | ||
] | ||
items = [ | ||
( | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
and some_var == "long strings" | ||
and {"key": "val"} | ||
), | ||
] | ||
items = [ | ||
( | ||
"123456890123457890123468901234567890" | ||
and some_var == "long strings" | ||
and "123467890123467890" | ||
) | ||
] | ||
items = [ | ||
( | ||
"123456890123457890123468901234567890" | ||
and some_var == "long strings" | ||
and "123467890123467890" | ||
), | ||
] | ||
|
||
items = [ | ||
( | ||
long_variable_name | ||
and even_longer_variable_name | ||
and yet_another_very_long_variable_name | ||
) | ||
] | ||
items = [ | ||
( | ||
long_variable_name | ||
and even_longer_variable_name | ||
and yet_another_very_long_variable_name | ||
), | ||
] | ||
|
||
|
||
# output | ||
items = [123] | ||
items = [True] | ||
items = [True] | ||
items = [(True,)] | ||
items = [()] | ||
|
||
items = [ | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
if some_var == "long strings" | ||
else {"key": "val"} | ||
] | ||
items = [ | ||
( | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
if some_var == "long strings" | ||
else {"key": "val"} | ||
), | ||
] | ||
items = [ | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
if some_var == "long strings" | ||
else {"key": "val"} | ||
] | ||
items = [{"key1": "val1", "key2": "val2"} if some_var == "" else {"key": "val"}] | ||
items = [{"key1": "val1", "key2": "val2"} if some_var == "" else {"key": "val"}] | ||
items = [ | ||
"123456890123457890123468901234567890" | ||
if some_var == "long strings" | ||
else "123467890123467890" | ||
] | ||
|
||
items = [ | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
and some_var == "long strings" | ||
and {"key": "val"} | ||
] | ||
items = [ | ||
( | ||
{"key1": "val1", "key2": "val2", "key3": "val3"} | ||
and some_var == "long strings" | ||
and {"key": "val"} | ||
), | ||
] | ||
items = [ | ||
"123456890123457890123468901234567890" | ||
and some_var == "long strings" | ||
and "123467890123467890" | ||
] | ||
items = [ | ||
( | ||
"123456890123457890123468901234567890" | ||
and some_var == "long strings" | ||
and "123467890123467890" | ||
), | ||
] | ||
|
||
items = [ | ||
long_variable_name | ||
and even_longer_variable_name | ||
and yet_another_very_long_variable_name | ||
] | ||
items = [ | ||
( | ||
long_variable_name | ||
and even_longer_variable_name | ||
and yet_another_very_long_variable_name | ||
), | ||
] |
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.