Skip to content
Open
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
9 changes: 7 additions & 2 deletions src/docformatter/format.py
Original file line number Diff line number Diff line change
Expand Up @@ -1065,8 +1065,13 @@ def _do_format_docstring( # noqa PLR0911
if not self.args.force_wrap and (
_patterns.is_type_of_list(
summary,
self.args.non_strict,
self.args.style,
# A wrapped summary can look like a list after the following
# prose is removed. Keep the heuristic for single-line summaries.
strict=self.args.non_strict
or (
"\n" in summary and not _patterns.is_heuristic_list(contents, False)
),
style=self.args.style,
)
or _patterns.do_find_links(summary)
):
Expand Down
32 changes: 32 additions & 0 deletions tests/test_oss_regression_265.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
"""Regression for a summary sentence split across short source lines."""

import sys

import pytest

from docformatter.format import Formatter


@pytest.mark.integration
@pytest.mark.parametrize("args", [[""]])
@pytest.mark.parametrize("continuation_indent", ["", " "])
def test_wrapped_summary_sentence(test_args, continuation_indent):
source = (
"def launch_rocket():\n"
' """Launch\n'
f"{continuation_indent}the\n"
f'{continuation_indent}rocket. Go colonize space."""\n'
)
expected = (
"def launch_rocket():\n"
' """Launch the rocket.\n'
"\n"
" Go colonize space.\n"
' """\n'
)
formatter = Formatter(test_args, sys.stderr, sys.stdin, sys.stdout)

formatted = formatter._do_format_code(source)

assert formatted == expected
assert formatter._do_format_code(formatted) == expected