Skip to content

Commit e1f3606

Browse files
Validate docstring directives
Fix pandas-dev#27629
1 parent 61362be commit e1f3606

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

scripts/validate_docstrings.py

+13
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,7 @@
9393
"GL07": "Sections are in the wrong order. Correct order is: " "{correct_sections}",
9494
"GL08": "The object does not have a docstring",
9595
"GL09": "Deprecation warning should precede extended summary",
96+
"GL10": "reST directives {directives} must be followed by two colons",
9697
"SS01": "No summary found (a short summary in a single line should be "
9798
"present at the beginning of the docstring)",
9899
"SS02": "Summary does not start with a capital letter",
@@ -239,6 +240,10 @@ def get_api_items(api_doc_fd):
239240

240241

241242
class Docstring:
243+
DIRECTIVES = ['deprecated', 'versionadded', 'versionchanged']
244+
DIRECTIVE_WITHOUT_TWO_COLONS = re.compile(
245+
rf"^\s*.. ({'|'.join(DIRECTIVES)})(?!::)", re.I | re.M)
246+
242247
def __init__(self, name):
243248
self.name = name
244249
obj = self._load_obj(name)
@@ -478,6 +483,10 @@ def parameter_mismatches(self):
478483
def correct_parameters(self):
479484
return not bool(self.parameter_mismatches)
480485

486+
@property
487+
def directives_without_two_colons(self):
488+
return Docstring.DIRECTIVE_WITHOUT_TWO_COLONS.findall(self.raw_doc)
489+
481490
def parameter_type(self, param):
482491
return self.doc_parameters[param][0]
483492

@@ -697,6 +706,10 @@ def get_validation_data(doc):
697706
if doc.deprecated and not doc.extended_summary.startswith(".. deprecated:: "):
698707
errs.append(error("GL09"))
699708

709+
directives_without_two_colons = doc.directives_without_two_colons
710+
if directives_without_two_colons:
711+
errs.append(error("GL10", directives=directives_without_two_colons))
712+
700713
if not doc.summary:
701714
errs.append(error("SS01"))
702715
else:

0 commit comments

Comments
 (0)