Skip to content

Commit fe95e8b

Browse files
amoebarossbar
andauthored
BUG: PR06 logic to only fail when type is used standalone (#447)
Change PR06 logic to only fail when type is used standalone. This prevents failures for user-defined classes, e.g. Mystring Co-authored-by: Ross Barnowski <[email protected]>
1 parent 11bab2e commit fe95e8b

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

numpydoc/tests/test_validate.py

Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -506,6 +506,40 @@ def parameters_with_trailing_underscores(self, str_):
506506
"""
507507
pass
508508

509+
def parameter_with_wrong_types_as_substrings(self, a, b, c, d, e, f):
510+
r"""
511+
Ensure PR06 doesn't fail when non-preferable types are substrings.
512+
513+
While PR06 checks for parameter types which contain non-preferable type
514+
names like integer (int), string (str), and boolean (bool), PR06 should
515+
not fail if those types are used only as susbtrings in, for example,
516+
custom type names.
517+
518+
Parameters
519+
----------
520+
a : Myint
521+
Some text.
522+
b : intClass
523+
Some text.
524+
c : Mystring
525+
Some text.
526+
d : stringClass
527+
Some text.
528+
e : Mybool
529+
Some text.
530+
f : boolClass
531+
Some text.
532+
533+
See Also
534+
--------
535+
related : Something related.
536+
537+
Examples
538+
--------
539+
>>> result = 1 + 1
540+
"""
541+
pass
542+
509543

510544
class BadGenericDocStrings:
511545
"""Everything here has a bad docstring"""
@@ -1145,6 +1179,7 @@ def test_good_class(self, capsys):
11451179
"warnings",
11461180
"valid_options_in_parameter_description_sets",
11471181
"parameters_with_trailing_underscores",
1182+
"parameter_with_wrong_types_as_substrings",
11481183
],
11491184
)
11501185
def test_good_functions(self, capsys, func):

numpydoc/validate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def validate(obj_name):
584584
("string", "str"),
585585
]
586586
for wrong_type, right_type in common_type_errors:
587-
if wrong_type in doc.parameter_type(param):
587+
if wrong_type in set(re.split(r"\W", doc.parameter_type(param))):
588588
errs.append(
589589
error(
590590
"PR06",

0 commit comments

Comments
 (0)