File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 2323# SOFTWARE.
2424"""This module provides docformatter string functions."""
2525
26+
27+ import contextlib
2628# Standard Library Imports
2729import re
2830
@@ -110,7 +112,13 @@ def normalize_summary(summary: str) -> str:
110112 and (not summary .startswith ("#" ))
111113 ):
112114 summary += "."
113- summary = summary [0 ].upper () + summary [1 :]
115+
116+ with contextlib .suppress (IndexError ):
117+ # Look for underscores in the first word, this would typically
118+ # indicate the first word is a variable name or some other
119+ # non-standard English word.
120+ if "_" not in summary .split (" " , 1 )[0 ]:
121+ summary = summary [0 ].upper () + summary [1 :]
114122
115123 return summary
116124
Original file line number Diff line number Diff line change @@ -206,6 +206,29 @@ def test_normalize_summary_capitalize_first_letter(self):
206206 "don't lower case I'm"
207207 )
208208
209+ @pytest .mark .unit
210+ def test_normalize_summary_capitalize_first_letter_with_period (self ):
211+ """Capitalize the first letter of the summary even when ends in period.
212+
213+ See issue #184. See requirement docformatter_4.5.1.
214+ """
215+ assert (
216+ "This is a summary that needs to be capped."
217+ == docformatter .normalize_summary (
218+ "this is a summary that needs to be capped."
219+ )
220+ )
221+
222+ @pytest .mark .unit
223+ def test_normalize_summary_dont_capitalize_first_letter_if_variable (self ):
224+ """Capitalize the first word unless it looks like a variable."""
225+ assert (
226+ "num_iterations should not be capitalized in this summary."
227+ == docformatter .normalize_summary (
228+ "num_iterations should not be capitalized in this summary"
229+ )
230+ )
231+
209232
210233class TestSplitters :
211234 """Class for testing the string splitting function.
You can’t perform that action at this time.
0 commit comments