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

Black doesn't delete trailing commas in dictionary when shrinking to one line #1312

Closed
rmorshea opened this issue Mar 21, 2020 · 4 comments
Closed
Labels
T: bug Something isn't working

Comments

@rmorshea
Copy link

Version: 19.10b

Given the following code:

[
    {
        "items": {
            "properties": {"type": {"const": "array"}},
            "required": ["type"],
        },
    }
]

Is shrunk to:

[{"items": {"properties": {"type": {"const": "array"}}, "required": ["type"],},}]

Which leaves a trailing commas in place that, according to flake8 (E231), ought to be removed.

@rmorshea rmorshea added the T: bug Something isn't working label Mar 21, 2020
@dandavison
Copy link
Contributor

I think this is a dup of #1288

Worse yet, in those cases it leaves trailing commas behind when a collection ends up compressed into one line.

@whatisaphone
Copy link

Prettier has a nice rule:

  • multiline sequences always have trailing commas
  • single-line sequences never have trailing commas

Easy, simple, consistent. I hope black considers adopting this.

In the meantime, you can "fix" this by downgrading:

pip install black==19.3b0

@rmorshea
Copy link
Author

Interesting. What feature-add introduced this bug?

@JelleZijlstra
Copy link
Collaborator

Yes, this is basically #1288. The behavior is an unfortunate consequence of #826.

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

4 participants