Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 15 additions & 2 deletions pydocstringformatter/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,21 @@ def _treat_summary(
) -> str:
"""Wrap the summary of a docstring."""

# We need to deduct ending quotes if there is no description
line_length = 88 if description_exists else 88 - quotes_length
line_length = 88

# Without a description we need to consider the length including closing quotes
if not description_exists:

# Calculate length without the ending quotes
length_without_ending = indent_length + quotes_length + len(summary)

# If potential length is less than line length we need to consider ending
# quotes as well for the line length
if length_without_ending < line_length:
# We substract one more because we don't want a new line with just the
# ending quotes
line_length -= quotes_length + 1

summary_lines = summary.splitlines()

new_summary = "\n".join(
Expand Down
14 changes: 14 additions & 0 deletions tests/data/format/linewrap_summary/function_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,17 @@ def func():
# exceeds the max length.
def func():
"""A multi-line summary that can be on one line. Something that is just too longgg."""


def func():
"""A multi-line summary that can be on one line. Something that is just too long."""


def func():
"""A multi-line summary that can be on one line. Something that is just too lon."""


# Regression for bug found in pylint
# We should re-add the quotes to line length if they will never be on the first line.
class LinesChunk:
"""The LinesChunk object computes and stores the hash of some consecutive stripped lines of a lineset."""
18 changes: 18 additions & 0 deletions tests/data/format/linewrap_summary/function_docstrings.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -29,3 +29,21 @@ def func():
"""A multi-line summary that can be on one line. Something that is just too
longgg.
"""


def func():
"""A multi-line summary that can be on one line. Something that is just too
long.
"""


def func():
"""A multi-line summary that can be on one line. Something that is just too lon."""


# Regression for bug found in pylint
# We should re-add the quotes to line length if they will never be on the first line.
class LinesChunk:
"""The LinesChunk object computes and stores the hash of some consecutive stripped
lines of a lineset.
"""