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

Unnecessary linebreak in slice notation after a multiline string literal #4581

Closed
maple3142 opened this issue Feb 19, 2025 · 1 comment
Closed
Labels
T: style What do we want Blackened code to look like?

Comments

@maple3142
Copy link

Describe the style change

Current black format the slice notation just after a multiline string literal over multiple lines, but that's unnecessary when the line containing closing triple quote is short.

Examples in the current Black style

s = """
lorem ipsum dolor sit amet
consectetur adipiscing elit
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua
ut enim ad minim veniam
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo
consequat duis aute irure dolor in
reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur
excepteur sint occaecat cupidatat non
proident sunt in culpa qui officia
deserunt mollit anim id est laborum
"""[
    1:
]
print(s)

Desired style

s = """
lorem ipsum dolor sit amet
consectetur adipiscing elit
sed do eiusmod tempor incididunt
ut labore et dolore magna aliqua
ut enim ad minim veniam
quis nostrud exercitation ullamco
laboris nisi ut aliquip ex ea commodo
consequat duis aute irure dolor in
reprehenderit in voluptate velit esse
cillum dolore eu fugiat nulla pariatur
excepteur sint occaecat cupidatat non
proident sunt in culpa qui officia
deserunt mollit anim id est laborum
"""[1:]
print(s)

Additional context

@maple3142 maple3142 added the T: style What do we want Blackened code to look like? label Feb 19, 2025
@cobaltt7
Copy link
Collaborator

This issue is fixed in the currently unstable multiline_string_formatting style, togglable with --unstable or --preview --enable-unstable-feature multiline_string_formatting. It's still unstable due to it occasionally causing worse formatting, which is being tracked in #4159.

@cobaltt7 cobaltt7 closed this as not planned Won't fix, can't repro, duplicate, stale Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

2 participants