Black: Black Fails to Format Single String Longer Than Line Length Limit

Created on 2 Nov 2020  ·  2Comments  ·  Source: psf/black

Describe the bug
A Python file containing a single string assignment longer than the line length limit is not reformatted.

To Reproduce
Take long_line.py:

long = "This is a long line that is longer than 88 characters. I expect Black to shorten this line length."

Run Black:

$ black ./long_line.py 
All done! ✨ 🍰 ✨
1 file left unchanged.

Expected behavior
I expect black to shorten the line length to less than the length limit. One possible solution is to break on the <line length limit minus 1> character and parenthesize if it is not already inside parentheses:

long = (
    "This is a long line that is longer than 88 characters. I expect Black to shorten "
    "this line length."
)

Environment (please complete the following information):

$ black --version
black, version 20.8b1

OS: macOS Catalina 10.15.6

$ python --version
Python 3.8.5

Does this bug also happen on master?
Yes

Additional context
None

bug

Most helpful comment

This is currently implemented under the hidden --experimental-string-processing flag, which we'll hopefully be able to enable soon.

All 2 comments

This is currently implemented under the hidden --experimental-string-processing flag, which we'll hopefully be able to enable soon.

Confirmed that this works as expected.

$ black ./long_line.py --experimental-string-processing
reformatted long_line.py
All done! ✨ 🍰 ✨
1 file reformatted.
long = (
    "This is a long line that is longer than 88 characters. I expect Black to shorten"
    " this line length."
)
Was this page helpful?
0 / 5 - 0 ratings