Skip to content

style regression: too long single line docstrings have their quotes moved to a new line. #3320

@onerandomusername

Description

@onerandomusername

Describe the bug

Single-line docstrings that are longer than the line length have the final three " moved to a new line.

To Reproduce

For example, take this code:

from typing import Optional

# leaves this the same
def large_image_url(self) -> Optional[str]:
    """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# leaves this the same too
def large_image_url(self) -> Optional[str]:
    """
    Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# depending on the length of the docstring, this one *may* be left as-is
def large_image_url(self) -> Optional[str]:
    """
    Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable."""
    pass


# but this one is modified
def large_image_url(self) -> Optional[str]:
    """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable."""
    pass

And run it with these arguments:

$ black file.py --preview

We get this format:

from typing import Optional

# leaves this the same
def large_image_url(self) -> Optional[str]:
    """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# leaves this the same too
def large_image_url(self) -> Optional[str]:
    """
    Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# this one is also left as-is
def large_image_url(self) -> Optional[str]:
    """
    Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass


# but this one is modified
def large_image_url(self) -> Optional[str]:
    """Optional[:class:`str`]: Returns a URL pointing to the large image asset of this activity, if applicable.
    """
    pass

Expected behavior

Single line docstrings are left alone. I understand what this change is supposed to do, and on already multiline docstrings this wouldn't be an issue (although it would be nice for the docstring formatter to be entirely consistent among all docstrings instead of having different behavior for the line length but i digress).

Environment

  • Black's version: 22.10.0
  • OS and Python version: Python 3.11.0rc2, on linux, but i can recreate with python 3.8 too

Additional Comments

This seems like a regression from #3044

Metadata

Metadata

Assignees

No one assigned

    Labels

    F: docstringsHow we format docstringsF: linebreakHow should we split up lines?T: bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions