Skip to content
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

Issue with the "Magic Trailing Comma" in collections in function calls #1433

Closed
scolby33 opened this issue May 18, 2020 · 3 comments
Closed
Labels
T: bug Something isn't working

Comments

@scolby33
Copy link

Describe the bug Trailing commas are left in collections that remain on one line in a function call
To Reproduce Steps to reproduce the behavior:

  1. Take this file:
test_call(
    {"some_key": "some_value", "other_key": "other_value",}
)

This also happens with the set literal {"some_key", "some_value", "other_key", "other_value",} and the list literal ["some_key", "some_value", "other_key", "other_value",].

  1. Run Black on it with these arguments black black_test.py
  2. See error: the file is unchanged

Expected behavior
Based on the documentation on trailing commas, I would expect the final comma after "other_value" to be removed.

Unnecessary trailing commas are removed if an expression fits in one line.

This case doesn't match either of the stated exceptions: it is neither a tuple expression with one element nor a function signature with a *.

Based on the documentation on the magic trailing comma, I would expect the dictionary literal to be expanded to multiple lines.

Now, you can communicate that you don't want [the literal collapsed to one line] by putting a trailing comma in the collection yourself. When you do, Black will know to always explode your collection into one item per line.

Environment (please complete the following information):

  • Version: 19.10b0, installed via pipx
  • OS and Python version: macOS 10.15.4 with Python 3.8.2 installed via pyenv

Does this bug also happen on master? Yes: tested on the Black Playground

@scolby33 scolby33 added the T: bug Something isn't working label May 18, 2020
@ichard26
Copy link
Collaborator

Seems rather similar to #1169.

@scolby33
Copy link
Author

Agreed! Please close as a dupe if appropriate. I missed that issue in my search before submitting this.

@cooperlees
Copy link
Collaborator

Duplicate of #1169

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants