Skip to content

Commit a4fa470

Browse files
Pierre-SassoulasDanielNoord
authored andcommitted
Create a constant for duplicated end of sentence punctuation
Follow-up to #49
1 parent 06078cf commit a4fa470

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

pydocstringformatter/formatting/formatter.py

+6-2
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ class FinalPeriodFormatter(StringAndQuotesFormatter):
6565
"""Add a period to the end of single line docstrings and summaries."""
6666

6767
name = "final-period"
68+
END_OF_SENTENCE_PUNCTUATION = {".", "?", "!", "‽"}
6869

6970
def _treat_string(
7071
self,
@@ -76,7 +77,10 @@ def _treat_string(
7677
"""Add a period to the end of single-line docstrings and summaries."""
7778
# Handle single line docstrings
7879
if not tokeninfo.string.count("\n"):
79-
if tokeninfo.string[-quotes_length - 1] not in {".", "?", "!", "‽"}:
80+
if (
81+
tokeninfo.string[-quotes_length - 1]
82+
not in self.END_OF_SENTENCE_PUNCTUATION
83+
):
8084
return tokeninfo.string[:-quotes_length] + "." + quotes
8185
# Handle multi-line docstrings
8286
else:
@@ -88,7 +92,7 @@ def _treat_string(
8892
return tokeninfo.string
8993
# If second line is empty we're dealing with a summary
9094
if lines[1] == "":
91-
if lines[0][-1] not in {".", "?", "!", "‽"}:
95+
if lines[0][-1] not in self.END_OF_SENTENCE_PUNCTUATION:
9296
return lines[0] + ".\n" + "\n".join(lines[1:])
9397
# TODO(#26): Handle multi-line docstrings that do not have a summary
9498
# This is obviously dependent on whether 'pydocstringformatter' will

0 commit comments

Comments
 (0)