From cdfd705b59bdf11db6112b76f151aab89eced9be Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Fri, 6 Jan 2023 15:04:41 -0900 Subject: [PATCH 1/3] Change PR06 logic to only fail when type is used standalone Closes https://github.com/numpy/numpydoc/issues/446 --- numpydoc/tests/test_validate.py | 35 +++++++++++++++++++++++++++++++++ numpydoc/validate.py | 10 +++++++++- 2 files changed, 44 insertions(+), 1 deletion(-) diff --git a/numpydoc/tests/test_validate.py b/numpydoc/tests/test_validate.py index 080affab..87daee17 100644 --- a/numpydoc/tests/test_validate.py +++ b/numpydoc/tests/test_validate.py @@ -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""" @@ -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): diff --git a/numpydoc/validate.py b/numpydoc/validate.py index cc058f0d..ea785e6f 100644 --- a/numpydoc/validate.py +++ b/numpydoc/validate.py @@ -584,7 +584,15 @@ def validate(obj_name): ("string", "str"), ] for wrong_type, right_type in common_type_errors: - if wrong_type in doc.parameter_type(param): + param_type = doc.parameter_type(param) + if wrong_type in param_type: + # Ignore if wrong_type is used as a substring + if ( + re.match(f"\w+{wrong_type}", param_type) or + re.match(f"{wrong_type}\w+", param_type) + ): + continue + errs.append( error( "PR06", From 0990db168b26ba6aa29a2e2276a753ad4919c704 Mon Sep 17 00:00:00 2001 From: Bryce Mecum Date: Mon, 23 Jan 2023 12:20:31 -0900 Subject: [PATCH 2/3] Simplify common_type_error validation logic As per feedback in https://github.com/numpy/numpydoc/pull/447 --- numpydoc/validate.py | 11 ++--------- 1 file changed, 2 insertions(+), 9 deletions(-) diff --git a/numpydoc/validate.py b/numpydoc/validate.py index ea785e6f..ea472eee 100644 --- a/numpydoc/validate.py +++ b/numpydoc/validate.py @@ -584,15 +584,8 @@ def validate(obj_name): ("string", "str"), ] for wrong_type, right_type in common_type_errors: - param_type = doc.parameter_type(param) - if wrong_type in param_type: - # Ignore if wrong_type is used as a substring - if ( - re.match(f"\w+{wrong_type}", param_type) or - re.match(f"{wrong_type}\w+", param_type) - ): - continue - + if wrong_type in set(re.split(r"\W", doc.parameter_type( + param))): errs.append( error( "PR06", From 9d0bab831f5f4dd73048b48afe5cb2d4f1ff194e Mon Sep 17 00:00:00 2001 From: Ross Barnowski Date: Mon, 23 Jan 2023 23:05:20 -0800 Subject: [PATCH 3/3] STY: Run black. --- numpydoc/validate.py | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/numpydoc/validate.py b/numpydoc/validate.py index ea472eee..b975f831 100644 --- a/numpydoc/validate.py +++ b/numpydoc/validate.py @@ -584,8 +584,7 @@ def validate(obj_name): ("string", "str"), ] for wrong_type, right_type in common_type_errors: - if wrong_type in set(re.split(r"\W", doc.parameter_type( - param))): + if wrong_type in set(re.split(r"\W", doc.parameter_type(param))): errs.append( error( "PR06",