Skip to content

Commit

Permalink
Allow lists of default values in parameter documentation for Numpy (
Browse files Browse the repository at this point in the history
  • Loading branch information
DanielNoord authored and Pierre-Sassoulas committed Jul 17, 2022
1 parent 081e4d5 commit 40e08d1
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 3 deletions.
4 changes: 4 additions & 0 deletions doc/whatsnew/2/2.14/full.rst
Expand Up @@ -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?
----------------------------
Expand Down
17 changes: 14 additions & 3 deletions pylint/extensions/_check_docs_utils.py
Expand Up @@ -727,11 +727,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,
)
Expand Down
Expand Up @@ -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

0 comments on commit 40e08d1

Please sign in to comment.