Skip to content
This repository was archived by the owner on Nov 3, 2023. It is now read-only.

Commit 2f7a140

Browse files
committed
Validate only one blank between summary and detail
The previous implementation checked that at least one blank line existed between the summary line and the detail section for a multi-line docstring, but multiple separating blank lines were also allowed.
1 parent 4626bc1 commit 2f7a140

File tree

3 files changed

+31
-6
lines changed

3 files changed

+31
-6
lines changed

docs/snippets/error_code_table.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@
2121
+--------------+--------------------------------------------------------------+
2222
| D204 | 1 blank required after class docstring. |
2323
+--------------+--------------------------------------------------------------+
24-
| D205 | Blank line required between one-line summary and description.|
24+
| D205 | 1 blank required between summary line and description. |
2525
+--------------+--------------------------------------------------------------+
2626
| D206 | Docstring should be indented with spaces, not tabs. |
2727
+--------------+--------------------------------------------------------------+

pep257.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -724,7 +724,7 @@ def check_blank_before_after_class(slef, class_, docstring):
724724

725725
@check_for(Definition)
726726
def check_blank_after_summary(self, definition, docstring):
727-
"""D205: Blank line missing between one-line summary and description.
727+
"""D205: Put one blank line between summary line and description.
728728
729729
Multi-line docstrings consist of a summary line just like a one-line
730730
docstring, followed by a blank line, followed by a more elaborate
@@ -735,8 +735,13 @@ def check_blank_after_summary(self, definition, docstring):
735735
"""
736736
if docstring:
737737
lines = eval(docstring).strip().split('\n')
738-
if len(lines) > 1 and not is_blank(lines[1]):
739-
return Error()
738+
if len(lines) > 1:
739+
post_summary_blanks = list(map(is_blank, lines[1:]))
740+
blanks_count = sum(takewhile(bool, post_summary_blanks))
741+
if blanks_count != 1:
742+
yield Error('D205: Expected 1 blank line between summary '
743+
'line and description, found %s' %
744+
blanks_count)
740745

741746
@check_for(Definition)
742747
def check_indent(self, definition, docstring):

test.py

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -105,14 +105,34 @@ class LeadingAndTrailingSpaceMissing:
105105
pass
106106

107107

108-
@expect('D205: Blank line missing between one-line summary and description')
109-
def asdfasdf():
108+
@expect('D205: Expected 1 blank line between summary line and description, '
109+
'found 0')
110+
def multi_line_zero_separating_blanks():
110111
"""Summary.
111112
Description.
112113
113114
"""
114115

115116

117+
@expect('D205: Expected 1 blank line between summary line and description, '
118+
'found 2')
119+
def multi_line_two_separating_blanks():
120+
"""Summary.
121+
122+
123+
Description.
124+
125+
"""
126+
127+
128+
def multi_line_one_separating_blanks():
129+
"""Summary.
130+
131+
Description.
132+
133+
"""
134+
135+
116136
@expect('D207: Docstring is under-indented')
117137
def asdfsdf():
118138
"""Summary.

0 commit comments

Comments
 (0)