Skip to content

DOC: Validate parameter types in docstrings (e.g. str instead of string) #23165

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Oct 21, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
41 changes: 40 additions & 1 deletion scripts/tests/test_validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -208,7 +208,7 @@ def mode(self, axis, numeric_only):

.. versionchanged:: 0.1.2

numeric_only : boolean
numeric_only : bool
Sentence ending in period, followed by multiple directives.

.. versionadded:: 0.1.2
Expand Down Expand Up @@ -455,6 +455,39 @@ def blank_lines(self, kind):
"""
pass

def integer_parameter(self, kind):
"""
Uses integer instead of int.

Parameters
----------
kind : integer
Foo bar baz.
"""
pass

def string_parameter(self, kind):
"""
Uses string instead of str.

Parameters
----------
kind : string
Foo bar baz.
"""
pass

def boolean_parameter(self, kind):
"""
Uses boolean instead of bool.

Parameters
----------
kind : boolean
Foo bar baz.
"""
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add one test or two for something like list of boolean, integer, float or string... I think it makes sense to make sure that we capture them, and that the error in this case makes sense.

pass


class BadReturns(object):

Expand Down Expand Up @@ -590,6 +623,12 @@ def test_bad_generic_functions(self, func):
('Parameter "kind" description should finish with "."',)),
('BadParameters', 'parameter_capitalization',
('Parameter "kind" description should start with a capital letter',)),
('BadParameters', 'integer_parameter',
('Parameter "kind" type should be "int" instead of "integer"',)),
('BadParameters', 'string_parameter',
('Parameter "kind" type should be "str" instead of "string"',)),
('BadParameters', 'boolean_parameter',
('Parameter "kind" type should be "bool" instead of "boolean"',)),
pytest.param('BadParameters', 'blank_lines', ('No error yet?',),
marks=pytest.mark.xfail),
# Returns tests
Expand Down
11 changes: 10 additions & 1 deletion scripts/validate_docstrings.py
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,16 @@ def validate_one(func_name):
if doc.parameter_type(param)[-1] == '.':
param_errs.append('Parameter "{}" type should '
'not finish with "."'.format(param))

common_type_errors = [('integer', 'int'),
('boolean', 'bool'),
('string', 'str')]
for incorrect_type, correct_type in common_type_errors:
if incorrect_type in doc.parameter_type(param):
param_errs.append('Parameter "{}" type should be '
'"{}" instead of "{}"'
.format(param,
correct_type,
incorrect_type))
if not doc.parameter_desc(param):
param_errs.append('Parameter "{}" '
'has no description'.format(param))
Expand Down