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
18 changes: 18 additions & 0 deletions src/docformatter/strings.py
Original file line number Diff line number Diff line change
Expand Up @@ -455,10 +455,28 @@ def do_split_summary(lines) -> List[str]:
f"{_leading_spaces}{rest_text}{_internal_spaces}"
f"{lines[_pos + 1].strip()}"
)
elif _ends_summary_before_new_sentence(lines):
lines.insert(1, "")

return lines


def _ends_summary_before_new_sentence(lines) -> bool:
"""Check if the first line is a sentence and the second one starts another.

Only matters when a blank line follows later, since the summary would otherwise run
up to that blank line.
"""
return (
len(lines) > 2 # noqa: PLR2004
and any(not line.strip() for line in lines[2:])
and lines[0].endswith(".")
and not lines[0].endswith(ABBREVIATIONS)
and lines[0].count("``") % 2 == 0
and lines[1].lstrip()[:1].isupper()
)


def do_split_summary_and_description(contents):
"""Split docstring into summary and description.

Expand Down
18 changes: 18 additions & 0 deletions tests/_data/string_files/do_format_code.toml
Original file line number Diff line number Diff line change
Expand Up @@ -1348,3 +1348,21 @@ expected='''def foo():
a
""")
'''
[issue_315]
source='''def length_hint(obj, default=0):
"""
Return an estimate of the number of items in obj.
This is useful for presizing containers when building from an iterable.

If the object supports len(), the result will be exact.
"""
'''
expected='''def length_hint(obj, default=0):
"""Return an estimate of the number of items in obj.

This is useful for presizing containers when building from an
iterable.

If the object supports len(), the result will be exact.
"""
'''
1 change: 1 addition & 0 deletions tests/formatter/test_do_format_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,7 @@
("issue_366_triple_quote_in_parens_not_docstring", NO_ARGS),
("issue_343_return_raw_string", NO_ARGS),
("issue_343_call_argument", NO_ARGS),
("issue_315", NO_ARGS),
],
)
def test_do_format_code(test_key, test_args, args):
Expand Down