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

Trailing commas not removed when dict/function call collapsed into single line #3229

Closed
ghost opened this issue Aug 18, 2022 · 1 comment · Fixed by #3370
Closed

Trailing commas not removed when dict/function call collapsed into single line #3229

ghost opened this issue Aug 18, 2022 · 1 comment · Fixed by #3370
Labels
F: trailing comma Full of magic T: bug Something isn't working

Comments

@ghost
Copy link

ghost commented Aug 18, 2022

Describe the bug

When a multiline dict/function call is collapsed into fewer lines by black, it seems to leave stray trailing commas. This does not happen when using --skip-magic-trailing-comma.

To Reproduce

For example, take this code:

def refresh_token(self, device_family, refresh_token, api_key):
    return self.orchestration.refresh_token(
        data={
            "refreshToken": refresh_token,
        },
        api_key=api_key,
    )["extensions"]["sdk"]["token"]

And run it with these arguments:

$ black file.py -l 120

The resulting output is:

def refresh_token(self, device_family, refresh_token, api_key):
    return self.orchestration.refresh_token(data={"refreshToken": refresh_token,}, api_key=api_key,)["extensions"][
        "sdk"
    ]["token"]

Expected behavior

The output should look something like this (without the stray trailing commas):

def refresh_token(self, device_family, refresh_token, api_key):
    return self.orchestration.refresh_token(data={"refreshToken": refresh_token}, api_key=api_key)["extensions"][
        "sdk"
    ]["token"]

Environment

  • Black's version: 22.6.0 / main
  • OS and Python version: Debian 10, Python 3.10.4

Additional context

@ghost ghost added the T: bug Something isn't working label Aug 18, 2022
@ichard26 ichard26 added the F: trailing comma Full of magic label Aug 27, 2022
@ichard26
Copy link
Collaborator

Looks similar to #2052. Thanks for reporting by the way!

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

Successfully merging a pull request may close this issue.

1 participant