Skip to content

Commit 3ffbd69

Browse files
MoisanJustinZhengBC
authored andcommitted
DOC: Validate parameter types in docstrings (e.g. str instead of string) (pandas-dev#23165)
1 parent 39181c4 commit 3ffbd69

File tree

2 files changed

+67
-2
lines changed

2 files changed

+67
-2
lines changed

scripts/tests/test_validate_docstrings.py

+57-1
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ def mode(self, axis, numeric_only):
208208
209209
.. versionchanged:: 0.1.2
210210
211-
numeric_only : boolean
211+
numeric_only : bool
212212
Sentence ending in period, followed by multiple directives.
213213
214214
.. versionadded:: 0.1.2
@@ -455,6 +455,50 @@ def blank_lines(self, kind):
455455
"""
456456
pass
457457

458+
def integer_parameter(self, kind):
459+
"""
460+
Uses integer instead of int.
461+
462+
Parameters
463+
----------
464+
kind : integer
465+
Foo bar baz.
466+
"""
467+
pass
468+
469+
def string_parameter(self, kind):
470+
"""
471+
Uses string instead of str.
472+
473+
Parameters
474+
----------
475+
kind : string
476+
Foo bar baz.
477+
"""
478+
pass
479+
480+
def boolean_parameter(self, kind):
481+
"""
482+
Uses boolean instead of bool.
483+
484+
Parameters
485+
----------
486+
kind : boolean
487+
Foo bar baz.
488+
"""
489+
pass
490+
491+
def list_incorrect_parameter_type(self, kind):
492+
"""
493+
Uses list of boolean instead of list of bool.
494+
495+
Parameters
496+
----------
497+
kind : list of boolean, integer, float or string
498+
Foo bar baz.
499+
"""
500+
pass
501+
458502

459503
class BadReturns(object):
460504

@@ -590,6 +634,18 @@ def test_bad_generic_functions(self, func):
590634
('Parameter "kind" description should finish with "."',)),
591635
('BadParameters', 'parameter_capitalization',
592636
('Parameter "kind" description should start with a capital letter',)),
637+
('BadParameters', 'integer_parameter',
638+
('Parameter "kind" type should use "int" instead of "integer"',)),
639+
('BadParameters', 'string_parameter',
640+
('Parameter "kind" type should use "str" instead of "string"',)),
641+
('BadParameters', 'boolean_parameter',
642+
('Parameter "kind" type should use "bool" instead of "boolean"',)),
643+
('BadParameters', 'list_incorrect_parameter_type',
644+
('Parameter "kind" type should use "bool" instead of "boolean"',)),
645+
('BadParameters', 'list_incorrect_parameter_type',
646+
('Parameter "kind" type should use "int" instead of "integer"',)),
647+
('BadParameters', 'list_incorrect_parameter_type',
648+
('Parameter "kind" type should use "str" instead of "string"',)),
593649
pytest.param('BadParameters', 'blank_lines', ('No error yet?',),
594650
marks=pytest.mark.xfail),
595651
# Returns tests

scripts/validate_docstrings.py

+10-1
Original file line numberDiff line numberDiff line change
@@ -464,7 +464,16 @@ def validate_one(func_name):
464464
if doc.parameter_type(param)[-1] == '.':
465465
param_errs.append('Parameter "{}" type should '
466466
'not finish with "."'.format(param))
467-
467+
common_type_errors = [('integer', 'int'),
468+
('boolean', 'bool'),
469+
('string', 'str')]
470+
for incorrect_type, correct_type in common_type_errors:
471+
if incorrect_type in doc.parameter_type(param):
472+
param_errs.append('Parameter "{}" type should use '
473+
'"{}" instead of "{}"'
474+
.format(param,
475+
correct_type,
476+
incorrect_type))
468477
if not doc.parameter_desc(param):
469478
param_errs.append('Parameter "{}" '
470479
'has no description'.format(param))

0 commit comments

Comments
 (0)