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
20 changes: 13 additions & 7 deletions pydocstringformatter/formatting/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ def _treat_description(self, description: str, indent_length: int) -> str:
@staticmethod
def _separate_summary_and_description(
docstring: str, indent_length: int, quotes_length: Literal[1, 3]
) -> Tuple[str, Optional[str]]:
) -> Tuple[str, str, Optional[str]]:
"""Split the summary and description and handle quotes and indentation."""
if "\n\n" in docstring:
summary, description = docstring.split("\n\n", maxsplit=1)
Expand All @@ -132,7 +132,16 @@ def _separate_summary_and_description(
if summary.endswith("\n"):
summary = summary[:-1]

return summary, description
# Remove opening quotes
summary = summary[quotes_length:]

# Prefix is the new-line + idententation for summaries that
# are not on the same line as the opening quotes
prefix = ""
if summary.startswith("\n"):
prefix = "\n" + indent_length * " "
summary = summary[1 + indent_length :]
return prefix, summary, description

def _treat_string(
self,
Expand All @@ -141,17 +150,14 @@ def _treat_string(
quotes: str,
quotes_length: Literal[1, 3],
) -> str:
summary, description = self._separate_summary_and_description(
prefix, summary, description = self._separate_summary_and_description(
tokeninfo.string,
indent_length,
quotes_length,
)

# Remove opening quotes
summary = summary[quotes_length:]

new_summary = self._treat_summary(summary, indent_length)
docstring = f"{quotes}{new_summary}"
docstring = f"{quotes}{prefix}{new_summary}"

if description:
new_description = self._treat_description(description, indent_length)
Expand Down
8 changes: 8 additions & 0 deletions tests/data/format/summary_splitter/function_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,3 +26,11 @@ def func():
def inner_func():
"""Summary.
Body without period"""


def func():
"""
Summary.

Body of the docstring.
"""
8 changes: 8 additions & 0 deletions tests/data/format/summary_splitter/function_docstrings.py.out
Original file line number Diff line number Diff line change
Expand Up @@ -42,3 +42,11 @@ def func():

Body without period
"""


def func():
"""
Summary.

Body of the docstring.
"""