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

A comma should only be considered magical if followed by a newline #2354

Closed
graingert opened this issue Jul 2, 2021 · 7 comments
Closed
Labels
F: trailing comma Full of magic R: rejected This will not be worked on T: style What do we want Blackened code to look like?

Comments

@graingert
Copy link
Contributor

I think there's something here. A comma should only be considered magical if followed by a newline

Originally posted by @graingert in #2353 (comment)

@graingert
Copy link
Contributor Author

graingert commented Jul 2, 2021

Eg I think:
Before

x = {'a':42}
y = {'a':42,}
z = {'a':42,
}

After

x = {'a':42}
y = {'a':42}
z = {
    'a':42,
}

Is more understandable behaviour for black

@graingert
Copy link
Contributor Author

Or more specifically any whitespace including newlines before any other character

@felix-hilden felix-hilden added F: trailing comma Full of magic T: style What do we want Blackened code to look like? labels Jul 2, 2021
@felix-hilden
Copy link
Collaborator

This actually seems pretty reasonable, although I haven't really thought it through carefully.

@graingert
Copy link
Contributor Author

graingert commented Jul 3, 2021

I just found a counter-example:

            self.lifespan_context = _wrap_gen_lifespan_context(
                lifespan,  # type: ignore[arg-type]
            )

@graingert
Copy link
Contributor Author

so I think a narrower definition is to define a comma followed by a paren, bracket or brace as non-magical

@graingert
Copy link
Contributor Author

graingert commented Jul 3, 2021

eg:

# magic:
            self.lifespan_context = _wrap_gen_lifespan_context(
                lifespan,  # type: ignore[arg-type]
            )
# magic:
            self.lifespan_context = _wrap_gen_lifespan_context(
                lifespan,  # type: ignore[arg-type])
# maybe not magic:
            self.lifespan_context = _wrap_gen_lifespan_context(
                lifespan,  )
# probably not magic:
            self.lifespan_context = _wrap_gen_lifespan_context(
                lifespan,)
# not magic:
            self.lifespan_context = _wrap_gen_lifespan_context(lifespan,     )
# not magic:
            self.lifespan_context = _wrap_gen_lifespan_context(lifespan,)

@hauntsaninja hauntsaninja added the R: rejected This will not be worked on label Jun 29, 2023
@hauntsaninja
Copy link
Collaborator

It should be easy for humans to simulate Black's formatting, and I think this proposal crosses a complexity boundary. The magic trailing comma is already pretty magical and paying even more attention to existing formatting introduces more implementation complexity.

@hauntsaninja hauntsaninja closed this as not planned Won't fix, can't repro, duplicate, stale Jun 29, 2023
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 R: rejected This will not be worked on T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

3 participants