black
black copied to clipboard
Unnecessary split in left hand side of assignment due to multiline string
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
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.
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.
Duplicate of #236 and #256.