Skip to content

Commit

Permalink
BUG: PR06 logic to only fail when type is used standalone (#447)
Browse files Browse the repository at this point in the history
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 <rossbar@berkeley.edu>
  • Loading branch information
amoeba and rossbar committed Jan 24, 2023
1 parent 11bab2e commit fe95e8b
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 1 deletion.
35 changes: 35 additions & 0 deletions numpydoc/tests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -506,6 +506,40 @@ def parameters_with_trailing_underscores(self, str_):
"""
pass

def parameter_with_wrong_types_as_substrings(self, a, b, c, d, e, f):
r"""
Ensure PR06 doesn't fail when non-preferable types are substrings.
While PR06 checks for parameter types which contain non-preferable type
names like integer (int), string (str), and boolean (bool), PR06 should
not fail if those types are used only as susbtrings in, for example,
custom type names.
Parameters
----------
a : Myint
Some text.
b : intClass
Some text.
c : Mystring
Some text.
d : stringClass
Some text.
e : Mybool
Some text.
f : boolClass
Some text.
See Also
--------
related : Something related.
Examples
--------
>>> result = 1 + 1
"""
pass


class BadGenericDocStrings:
"""Everything here has a bad docstring"""
Expand Down Expand Up @@ -1145,6 +1179,7 @@ def test_good_class(self, capsys):
"warnings",
"valid_options_in_parameter_description_sets",
"parameters_with_trailing_underscores",
"parameter_with_wrong_types_as_substrings",
],
)
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 @@ -584,7 +584,7 @@ def validate(obj_name):
("string", "str"),
]
for wrong_type, right_type in common_type_errors:
if wrong_type in doc.parameter_type(param):
if wrong_type in set(re.split(r"\W", doc.parameter_type(param))):
errs.append(
error(
"PR06",
Expand Down

0 comments on commit fe95e8b

Please sign in to comment.