From 254b260255e21f5bf7e3d10b82322a420df3cb85 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Dani=C3=ABl=20van=20Noord?= <13665637+DanielNoord@users.noreply.github.com> Date: Fri, 8 Jul 2022 22:57:00 +0200 Subject: [PATCH] Allow lists of default values in parameter documentation for ``Numpy`` (#7149) --- doc/whatsnew/2/2.14/full.rst | 4 ++++ pylint/extensions/_check_docs_utils.py | 17 ++++++++++++++--- .../missing_param_doc_required_Numpy.py | 15 +++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/doc/whatsnew/2/2.14/full.rst b/doc/whatsnew/2/2.14/full.rst index d318b3767d..26a6d6445e 100644 --- a/doc/whatsnew/2/2.14/full.rst +++ b/doc/whatsnew/2/2.14/full.rst @@ -17,6 +17,10 @@ Release date: TBA * Fixed the disabling of ``fixme`` and its interaction with ``useless-suppression``. +* Allow lists of default values in parameter documentation for ``Numpy`` style. + + Closes #4035 + What's New in Pylint 2.14.4? ---------------------------- diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index 3f4937f175..747fcb4ea0 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -728,11 +728,22 @@ class NumpyDocstring(GoogleDocstring): re.X | re.S | re.M, ) + re_default_value = r"""((['"]\w+\s*['"])|(True)|(False)|(None))""" + re_param_line = re.compile( rf""" - \s* (\*{{0,2}}\w+)(\s?(:|\n)) # identifier with potential asterisks - \s* (?:({GoogleDocstring.re_multiple_type})(?:,\s+optional)?\n)? # optional type declaration - \s* (.*) # optional description + \s* (\*{{0,2}}\w+)(\s?(:|\n)) # identifier with potential asterisks + \s* + ( + ( + ({GoogleDocstring.re_multiple_type}) # default type declaration + (,\s+optional)? # optional 'optional' indication + )? + ( + {{({re_default_value},?\s*)+}} # set of default values + )? + \n)? + \s* (.*) # optional description """, re.X | re.S, ) diff --git a/tests/functional/ext/docparams/parameter/missing_param_doc_required_Numpy.py b/tests/functional/ext/docparams/parameter/missing_param_doc_required_Numpy.py index c47d03c316..6e725980fb 100644 --- a/tests/functional/ext/docparams/parameter/missing_param_doc_required_Numpy.py +++ b/tests/functional/ext/docparams/parameter/missing_param_doc_required_Numpy.py @@ -391,3 +391,18 @@ def test_ignores_optional_specifier_numpy(param, param2="all"): Description. """ return param, param2 + +def test_with_list_of_default_values(arg, option, option2): + """Reported in https://github.com/PyCQA/pylint/issues/4035. + + Parameters + ---------- + arg : int + The number of times to print it. + option : {"y", "n"} + Do I do it? + option2 : {"y", None, "n"} + Do I do it? + + """ + return arg, option, option2