summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBryce Mecum <petridish@gmail.com>2023-01-24 12:55:44 -0900
committerGitHub <noreply@github.com>2023-01-24 13:55:44 -0800
commitfe95e8b9332ed4ebc154db08b00232f5f67f9330 (patch)
tree30b89030c75e3e6d9082aed635d75b139fd12995
parent11bab2e686d2e6df95bc412b08a8483b9d1c43b9 (diff)
downloadnumpydoc-fe95e8b9332ed4ebc154db08b00232f5f67f9330.tar.gz
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 <rossbar@berkeley.edu>
-rw-r--r--numpydoc/tests/test_validate.py35
-rw-r--r--numpydoc/validate.py2
2 files changed, 36 insertions, 1 deletions
diff --git a/numpydoc/tests/test_validate.py b/numpydoc/tests/test_validate.py
index 080affa..87daee1 100644
--- a/numpydoc/tests/test_validate.py
+++ b/numpydoc/tests/test_validate.py
@@ -506,6 +506,40 @@ class GoodDocStrings:
"""
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"""
@@ -1145,6 +1179,7 @@ class TestValidator:
"warnings",
"valid_options_in_parameter_description_sets",
"parameters_with_trailing_underscores",
+ "parameter_with_wrong_types_as_substrings",
],
)
def test_good_functions(self, capsys, func):
diff --git a/numpydoc/validate.py b/numpydoc/validate.py
index cc058f0..b975f83 100644
--- a/numpydoc/validate.py
+++ b/numpydoc/validate.py
@@ -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",