Skip to content

Fix validation bug when parameter type is set of options. #347

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 2 commits into from
Jan 7, 2022
Merged
Show file tree
Hide file tree
Changes from all 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
23 changes: 23 additions & 0 deletions numpydoc/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -458,6 +458,28 @@ def other_parameters(self, param1, param2):
"""
pass

def valid_options_in_parameter_description_sets(self, bar):
"""
Ensure a PR06 error is not raised when type is member of a set.

Literal keywords like 'integer' are valid when specified in a set of
valid options for a keyword parameter.

Parameters
----------
bar : {'integer', 'boolean'}
The literal values of 'integer' and 'boolean' are part of an
options set and thus should not be subject to PR06 warnings.

See Also
--------
related : Something related.

Examples
--------
>>> result = 1 + 1
"""


class BadGenericDocStrings:
"""Everything here has a bad docstring
Expand Down Expand Up @@ -1089,6 +1111,7 @@ def test_good_class(self, capsys):
"multiple_variables_on_one_line",
"other_parameters",
"warnings",
"valid_options_in_parameter_description_sets",
],
)
def test_good_functions(self, capsys, func):
Expand Down
4 changes: 4 additions & 0 deletions numpydoc/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -564,6 +564,10 @@ def validate(obj_name):
else:
if doc.parameter_type(param)[-1] == ".":
errs.append(error("PR05", param_name=param))
# skip common_type_error checks when the param type is a set of
# options
if "{" in doc.parameter_type(param):
continue
common_type_errors = [
("integer", "int"),
("boolean", "bool"),
Expand Down