Skip to content

Commit

Permalink
ENH: Update validate.py to allow parameters with trailing underscores. (
Browse files Browse the repository at this point in the history
#425)

* Update validate.py to allow parameters with trailing underscores.

* Add test to ensure that escaping trailing underscores in parameters is accounted for.

* Update test_validate.py

* Fix spacing in test case.

* Add parameters_with_trailing_underscores to test_good_functions()
  • Loading branch information
stefmolin committed Aug 25, 2022
1 parent 5720f08 commit 4ef89d4
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 1 deletion.
25 changes: 25 additions & 0 deletions numpydoc/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -482,6 +482,30 @@ def valid_options_in_parameter_description_sets(self, bar):
>>> result = 1 + 1
"""

def parameters_with_trailing_underscores(self, str_):
r"""
Ensure PR01 and PR02 errors are not raised with trailing underscores.
Parameters with trailing underscores need to be escaped to render
properly in the documentation since trailing underscores are used to
create links. Doing so without also handling the change in the validation
logic makes it impossible to both pass validation and render correctly.
Parameters
----------
str\_ : str
Some text.
See Also
--------
related : Something related.
Examples
--------
>>> result = 1 + 1
"""
pass


class BadGenericDocStrings:
"""Everything here has a bad docstring"""
Expand Down Expand Up @@ -1120,6 +1144,7 @@ def test_good_class(self, capsys):
"other_parameters",
"warnings",
"valid_options_in_parameter_description_sets",
"parameters_with_trailing_underscores",
],
)
def test_good_functions(self, capsys, func):
Expand Down
2 changes: 1 addition & 1 deletion numpydoc/validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -330,7 +330,7 @@ def add_stars(param_name, info):
def parameter_mismatches(self):
errs = []
signature_params = self.signature_parameters
all_params = tuple(self.doc_all_parameters)
all_params = tuple(param.replace("\\", "") for param in self.doc_all_parameters)
missing = set(signature_params) - set(all_params)
if missing:
errs.append(error("PR01", missing_params=str(missing)))
Expand Down

0 comments on commit 4ef89d4

Please sign in to comment.