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 split in left hand side of assignment due to multiline string #749

Closed
matejbasic opened this issue Mar 14, 2019 · 3 comments
Closed
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?

Comments

@matejbasic
Copy link

Hi, I'm experience strange behavior when I use dicts and triple-quotes strings, for example:

a["b"] = f"""Some really long
    long string."""

ends up like this:

a[
   "b"
] = f"""Some really long
    long string."""

Is it expected behavior or? If yes, how can one disable it?

Operating system: Linux Ubuntu 18.04
Python version: 3.6
Black version: 18.9b0
Does also happen on master: yes

@ambv
Copy link
Collaborator

ambv commented Mar 14, 2019

It's a bug. It stems from Black seeing that the right hand side doesn't fit in a line (it doesn't, it's a multiline string!) and tries to split the line by any other means.

In this case, it should recognize that the split made matters worse and abort. But that's not super easy to do at this point. We'll be fixing this though.

@JelleZijlstra JelleZijlstra added the T: style What do we want Blackened code to look like? label May 5, 2019
@ambv ambv changed the title Dict and triple-quotes strings Unnecessary split in left hand side of assignment due to multiline string Mar 4, 2020
@ambv ambv added the stable label Mar 4, 2020
@JelleZijlstra JelleZijlstra added the F: linebreak How should we split up lines? label May 30, 2021
@yilei
Copy link
Contributor

yilei commented Oct 11, 2022

This also happens to the right side:

a = """Not a so long string
  but multiline.""" + b.call(c=1)

is formatted to:

a = """Not a so long string
  but multiline.""" + b.call(
    c=1
)

even though it fits well within the line length.

@JelleZijlstra
Copy link
Collaborator

Duplicate of #236 and #256.

@JelleZijlstra JelleZijlstra closed this as not planned Won't fix, can't repro, duplicate, stale Dec 19, 2022
@ichard26 ichard26 added the R: duplicate This issue or pull request already exists label Dec 19, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
F: linebreak How should we split up lines? R: duplicate This issue or pull request already exists T: style What do we want Blackened code to look like?
Projects
None yet
Development

No branches or pull requests

6 participants