From fa283d5c108a0dbd3612f7a02f0a3afd6afaa1ec Mon Sep 17 00:00:00 2001 From: Danny Kim Date: Mon, 5 Nov 2018 19:28:26 +1100 Subject: [PATCH] DOC: Validate space before colon docstring parameters #23483 --- scripts/tests/test_validate_docstrings.py | 5 ++--- scripts/validate_docstrings.py | 9 ++++++++- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/scripts/tests/test_validate_docstrings.py b/scripts/tests/test_validate_docstrings.py index a3feee6552178..3908dfcd42a6a 100644 --- a/scripts/tests/test_validate_docstrings.py +++ b/scripts/tests/test_validate_docstrings.py @@ -719,9 +719,8 @@ def test_bad_generic_functions(self, func): ('BadParameters', 'missing_params', ('Parameters {**kwargs} not documented',)), ('BadParameters', 'bad_colon_spacing', - ('Parameters {kind} not documented', - 'Unknown parameters {kind: str}', - 'Parameter "kind: str" has no type')), + ('Parameter "kind" requires a space before the colon ' + 'separating the parameter name and type',)), ('BadParameters', 'no_description_period', ('Parameter "kind" description should finish with "."',)), ('BadParameters', 'no_description_period_with_directive', diff --git a/scripts/validate_docstrings.py b/scripts/validate_docstrings.py index ef6465c3e988d..a1aec381f30cd 100755 --- a/scripts/validate_docstrings.py +++ b/scripts/validate_docstrings.py @@ -488,7 +488,14 @@ def validate_one(func_name): for param in doc.doc_parameters: if not param.startswith("*"): # Check can ignore var / kwargs if not doc.parameter_type(param): - param_errs.append('Parameter "{}" has no type'.format(param)) + if ':' in param: + param_errs.append('Parameter "{}" requires a space ' + 'before the colon separating the ' + 'parameter name and type' + .format(param.split(':')[0])) + else: + param_errs.append('Parameter "{}" has no type' + .format(param)) else: if doc.parameter_type(param)[-1] == '.': param_errs.append('Parameter "{}" type should '