Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Test in scripts/validate_docstrings.py that the short summary is always one line long #22617

Merged
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
13 changes: 12 additions & 1 deletion scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -362,6 +362,15 @@ def multi_line(self):
which is not correct.
"""

def two_paragraph_multi_line(self):
"""
Extends beyond one line
which is not correct.

Extends beyond one line, which in itself is correct but the
previous short summary should still be an issue.
"""


class BadParameters(object):
"""
Expand Down Expand Up @@ -556,7 +565,9 @@ def test_bad_generic_functions(self, func):
('BadSummaries', 'no_capitalization',
('Summary must start with infinitive verb',)),
('BadSummaries', 'multi_line',
('a short summary in a single line should be present',)),
('Summary should fit in a single line.',)),
('BadSummaries', 'two_paragraph_multi_line',
('Summary should fit in a single line.',)),
# Parameters tests
('BadParameters', 'missing_params',
('Parameters {**kwargs} not documented',)),
Expand Down
8 changes: 6 additions & 2 deletions scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,10 +163,12 @@ def double_blank_lines(self):

@property
def summary(self):
if not self.doc['Extended Summary'] and len(self.doc['Summary']) > 1:
return ''
return ' '.join(self.doc['Summary'])

@property
def num_summary_lines(self):
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Overall approach is much cleaner here, though I'm maybe -0.5 on the property as I don't see this really being used outside of the one check you have, in which case you can probably just do len(self.doc['Summary']) directly

I'll defer to the @datapythonista on this one though

return len(self.doc['Summary'])

@property
def extended_summary(self):
if not self.doc['Extended Summary'] and len(self.doc['Summary']) > 1:
Expand Down Expand Up @@ -452,6 +454,8 @@ def validate_one(func_name):
errs.append('Summary must start with infinitive verb, '
'not third person (e.g. use "Generate" instead of '
'"Generates")')
if doc.num_summary_lines > 1:
errs.append("Summary should fit in a single line.")
if not doc.extended_summary:
wrns.append('No extended summary found')

Expand Down