diff --git a/src/docformatter/strings.py b/src/docformatter/strings.py index c6d1fb0..5f799ec 100644 --- a/src/docformatter/strings.py +++ b/src/docformatter/strings.py @@ -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. diff --git a/tests/_data/string_files/do_format_code.toml b/tests/_data/string_files/do_format_code.toml index 17b93a6..c2c17ba 100644 --- a/tests/_data/string_files/do_format_code.toml +++ b/tests/_data/string_files/do_format_code.toml @@ -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. + """ +''' diff --git a/tests/formatter/test_do_format_code.py b/tests/formatter/test_do_format_code.py index ef84584..a0d4c6d 100644 --- a/tests/formatter/test_do_format_code.py +++ b/tests/formatter/test_do_format_code.py @@ -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):