Skip to content

Docstring reformatting causes line to be too long #3331

@adamjstewart

Description

@adamjstewart

Describe the bug

Black is overzealous about reformatting docstrings to a single line, and can cause the resulting line to be longer than the line length limit.

To Reproduce

For example, take this code:

def f():
    """89 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678
    """

The first line of this docstring is exactly 88 characters. After blackening this code, this results in:

def f():
    """89 123456789 123456789 123456789 123456789 123456789 123456789 123456789 12345678"""

The line is now 91 characters, and flake8 complains.

Expected behavior

Honestly, I wouldn't expect black to reformat docstrings at all. But I definitely wouldn't expect it to reformat to the point where style-compliant code becomes non-style-compliant.

Environment

  • Black's version: 22.10.0, main
  • OS and Python version: macOS 12.6, Python 3.9.13

Additional context

This appears to be a regression of the same bug reported in #1632 and #2274.

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: docstringsHow we format docstringsR: outdatedResolved or not relevant anymore.T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions