78
78
'{allowed_sections}' ,
79
79
'GL07' : 'Sections are in the wrong order. Correct order is: '
80
80
'{correct_sections}' ,
81
+ 'GL08' : 'The object does not have a docstring' ,
81
82
'SS01' : 'No summary found (a short summary in a single line should be '
82
83
'present at the beginning of the docstring)' ,
83
84
'SS02' : 'Summary does not start with a capital letter' ,
@@ -545,20 +546,24 @@ def validate_pep8(self):
545
546
yield from application .guide .stats .statistics_for ('' )
546
547
547
548
548
- def validate_one ( func_name ):
549
+ def get_validation_data ( doc ):
549
550
"""
550
- Validate the docstring for the given func_name
551
+ Validate the docstring.
551
552
552
553
Parameters
553
554
----------
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 .
556
557
557
558
Returns
558
559
-------
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.
562
567
563
568
Notes
564
569
-----
@@ -585,10 +590,13 @@ def validate_one(func_name):
585
590
they are validated, are not documented more than in the source code of this
586
591
function.
587
592
"""
588
- doc = Docstring (func_name )
589
593
590
594
errs = []
591
595
wrns = []
596
+ if not doc .raw_doc :
597
+ errs .append (error ('GL08' ))
598
+ return errs , wrns , ''
599
+
592
600
if doc .start_blank_lines != 1 :
593
601
errs .append (error ('GL01' ))
594
602
if doc .end_blank_lines != 1 :
@@ -706,7 +714,26 @@ def validate_one(func_name):
706
714
for wrong_import in ('numpy' , 'pandas' ):
707
715
if 'import {}' .format (wrong_import ) in examples_source_code :
708
716
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
709
723
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 )
710
737
return {'type' : doc .type ,
711
738
'docstring' : doc .clean_doc ,
712
739
'deprecated' : doc .deprecated ,
0 commit comments