Skip to content

Commit 4ef89d4

Browse files
authored
ENH: Update validate.py to allow parameters with trailing underscores. (#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()
1 parent 5720f08 commit 4ef89d4

File tree

2 files changed

+26
-1
lines changed

2 files changed

+26
-1
lines changed

numpydoc/tests/test_validate.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -482,6 +482,30 @@ def valid_options_in_parameter_description_sets(self, bar):
482482
>>> result = 1 + 1
483483
"""
484484

485+
def parameters_with_trailing_underscores(self, str_):
486+
r"""
487+
Ensure PR01 and PR02 errors are not raised with trailing underscores.
488+
489+
Parameters with trailing underscores need to be escaped to render
490+
properly in the documentation since trailing underscores are used to
491+
create links. Doing so without also handling the change in the validation
492+
logic makes it impossible to both pass validation and render correctly.
493+
494+
Parameters
495+
----------
496+
str\_ : str
497+
Some text.
498+
499+
See Also
500+
--------
501+
related : Something related.
502+
503+
Examples
504+
--------
505+
>>> result = 1 + 1
506+
"""
507+
pass
508+
485509

486510
class BadGenericDocStrings:
487511
"""Everything here has a bad docstring"""
@@ -1120,6 +1144,7 @@ def test_good_class(self, capsys):
11201144
"other_parameters",
11211145
"warnings",
11221146
"valid_options_in_parameter_description_sets",
1147+
"parameters_with_trailing_underscores",
11231148
],
11241149
)
11251150
def test_good_functions(self, capsys, func):

numpydoc/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -330,7 +330,7 @@ def add_stars(param_name, info):
330330
def parameter_mismatches(self):
331331
errs = []
332332
signature_params = self.signature_parameters
333-
all_params = tuple(self.doc_all_parameters)
333+
all_params = tuple(param.replace("\\", "") for param in self.doc_all_parameters)
334334
missing = set(signature_params) - set(all_params)
335335
if missing:
336336
errs.append(error("PR01", missing_params=str(missing)))

0 commit comments

Comments
 (0)