Skip to content

Black Fails to Format Single String Longer Than Line Length Limit #1802

@kennytrytek-wf

Description

@kennytrytek-wf

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions