Skip to content

Commit 4d4b583

Browse files
datapythonistaJustinZhengBC
authored andcommitted
Fixing bug in validate_docstrings.py, where a bracket closed in the wrong place, raised a KeyError when a private class was found in a docstrings (and adding test for that case (pandas-dev#23543)
1 parent c611272 commit 4d4b583

File tree

2 files changed

+13
-3
lines changed

2 files changed

+13
-3
lines changed

scripts/tests/test_validate_docstrings.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -345,6 +345,11 @@ def method(self, foo=None, bar=None):
345345
"""
346346
pass
347347

348+
def private_classes(self):
349+
"""
350+
This mentions NDFrame, which is not correct.
351+
"""
352+
348353

349354
class BadSummaries(object):
350355

@@ -688,7 +693,8 @@ def test_bad_class(self):
688693

689694
@capture_stderr
690695
@pytest.mark.parametrize("func", [
691-
'func', 'astype', 'astype1', 'astype2', 'astype3', 'plot', 'method'])
696+
'func', 'astype', 'astype1', 'astype2', 'astype3', 'plot', 'method',
697+
'private_classes'])
692698
def test_bad_generic_functions(self, func):
693699
errors = validate_one(self._import_path( # noqa:F821
694700
klass='BadGenericDocStrings', func=func))['errors']
@@ -697,6 +703,9 @@ def test_bad_generic_functions(self, func):
697703

698704
@pytest.mark.parametrize("klass,func,msgs", [
699705
# See Also tests
706+
('BadGenericDocStrings', 'private_classes',
707+
("Private classes (NDFrame) should not be mentioned in public "
708+
'docstrings',)),
700709
('BadSeeAlso', 'desc_no_period',
701710
('Missing period at end of description for See Also "Series.iloc"',)),
702711
('BadSeeAlso', 'desc_first_letter_lowercase',

scripts/validate_docstrings.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -57,7 +57,7 @@
5757
'quotes)',
5858
'GL03': 'Use only one blank line to separate sections or paragraphs',
5959
'GL04': 'Private classes ({mentioned_private_classes}) should not be '
60-
'mentioned in public docstring',
60+
'mentioned in public docstrings',
6161
'GL05': 'Tabs found at the start of line "{line_with_tabs}", please use '
6262
'whitespace only',
6363
'SS01': 'No summary found (a short summary in a single line should be '
@@ -562,7 +562,8 @@ def validate_one(func_name):
562562
errs.append(error('GL03'))
563563
mentioned_errs = doc.mentioned_private_classes
564564
if mentioned_errs:
565-
errs.append(error('GL04'), mentioned_private_classes=mentioned_errs)
565+
errs.append(error('GL04',
566+
mentioned_private_classes=', '.join(mentioned_errs)))
566567
for line in doc.raw_doc.splitlines():
567568
if re.match("^ *\t", line):
568569
errs.append(error('GL05', line_with_tabs=line.lstrip()))

0 commit comments

Comments
 (0)