Skip to content

Commit 0cfd1c2

Browse files
avolkovjreback
authored andcommitted
Adding docstring validation error for when the function does not have a docstring (pandas-dev#23673)
1 parent 03134cb commit 0cfd1c2

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

scripts/tests/test_validate_docstrings.py

+5
Original file line numberDiff line numberDiff line change
@@ -407,6 +407,9 @@ def sections_in_wrong_order(self):
407407
before Examples.
408408
"""
409409

410+
def method_wo_docstrings(self):
411+
pass
412+
410413

411414
class BadSummaries(object):
412415

@@ -826,6 +829,8 @@ def test_bad_generic_functions(self, func):
826829
('Do not import numpy, as it is imported automatically',)),
827830
('BadGenericDocStrings', 'method',
828831
('Do not import pandas, as it is imported automatically',)),
832+
('BadGenericDocStrings', 'method_wo_docstrings',
833+
("The object does not have a docstring",)),
829834
# See Also tests
830835
('BadSeeAlso', 'prefix_pandas',
831836
('pandas.Series.rename in `See Also` section '

scripts/validate_docstrings.py

+35-8
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
'{allowed_sections}',
7979
'GL07': 'Sections are in the wrong order. Correct order is: '
8080
'{correct_sections}',
81+
'GL08': 'The object does not have a docstring',
8182
'SS01': 'No summary found (a short summary in a single line should be '
8283
'present at the beginning of the docstring)',
8384
'SS02': 'Summary does not start with a capital letter',
@@ -545,20 +546,24 @@ def validate_pep8(self):
545546
yield from application.guide.stats.statistics_for('')
546547

547548

548-
def validate_one(func_name):
549+
def get_validation_data(doc):
549550
"""
550-
Validate the docstring for the given func_name
551+
Validate the docstring.
551552
552553
Parameters
553554
----------
554-
func_name : function
555-
Function whose docstring will be evaluated (e.g. pandas.read_csv).
555+
doc : Docstring
556+
A Docstring object with the given function name.
556557
557558
Returns
558559
-------
559-
dict
560-
A dictionary containing all the information obtained from validating
561-
the docstring.
560+
tuple
561+
errors : list of tuple
562+
Errors occurred during validation.
563+
warnings : list of tuple
564+
Warnings occurred during validation.
565+
examples_errs : str
566+
Examples usage displayed along the error, otherwise empty string.
562567
563568
Notes
564569
-----
@@ -585,10 +590,13 @@ def validate_one(func_name):
585590
they are validated, are not documented more than in the source code of this
586591
function.
587592
"""
588-
doc = Docstring(func_name)
589593

590594
errs = []
591595
wrns = []
596+
if not doc.raw_doc:
597+
errs.append(error('GL08'))
598+
return errs, wrns, ''
599+
592600
if doc.start_blank_lines != 1:
593601
errs.append(error('GL01'))
594602
if doc.end_blank_lines != 1:
@@ -706,7 +714,26 @@ def validate_one(func_name):
706714
for wrong_import in ('numpy', 'pandas'):
707715
if 'import {}'.format(wrong_import) in examples_source_code:
708716
errs.append(error('EX04', imported_library=wrong_import))
717+
return errs, wrns, examples_errs
718+
719+
720+
def validate_one(func_name):
721+
"""
722+
Validate the docstring for the given func_name
709723
724+
Parameters
725+
----------
726+
func_name : function
727+
Function whose docstring will be evaluated (e.g. pandas.read_csv).
728+
729+
Returns
730+
-------
731+
dict
732+
A dictionary containing all the information obtained from validating
733+
the docstring.
734+
"""
735+
doc = Docstring(func_name)
736+
errs, wrns, examples_errs = get_validation_data(doc)
710737
return {'type': doc.type,
711738
'docstring': doc.clean_doc,
712739
'deprecated': doc.deprecated,

0 commit comments

Comments
 (0)