Skip to content

Commit

Permalink
Create a constant for duplicated end of sentence punctuation
Browse files Browse the repository at this point in the history
Follow-up to #49
  • Loading branch information
Pierre-Sassoulas authored and DanielNoord committed Feb 10, 2022
1 parent 06078cf commit a4fa470
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions pydocstringformatter/formatting/formatter.py
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ class FinalPeriodFormatter(StringAndQuotesFormatter):
"""Add a period to the end of single line docstrings and summaries."""

name = "final-period"
END_OF_SENTENCE_PUNCTUATION = {".", "?", "!", "‽"}

def _treat_string(
self,
Expand All @@ -76,7 +77,10 @@ def _treat_string(
"""Add a period to the end of single-line docstrings and summaries."""
# Handle single line docstrings
if not tokeninfo.string.count("\n"):
if tokeninfo.string[-quotes_length - 1] not in {".", "?", "!", "‽"}:
if (
tokeninfo.string[-quotes_length - 1]
not in self.END_OF_SENTENCE_PUNCTUATION
):
return tokeninfo.string[:-quotes_length] + "." + quotes
# Handle multi-line docstrings
else:
Expand All @@ -88,7 +92,7 @@ def _treat_string(
return tokeninfo.string
# If second line is empty we're dealing with a summary
if lines[1] == "":
if lines[0][-1] not in {".", "?", "!", "‽"}:
if lines[0][-1] not in self.END_OF_SENTENCE_PUNCTUATION:
return lines[0] + ".\n" + "\n".join(lines[1:])
# TODO(#26): Handle multi-line docstrings that do not have a summary
# This is obviously dependent on whether 'pydocstringformatter' will
Expand Down

0 comments on commit a4fa470

Please sign in to comment.