summaryrefslogtreecommitdiff
path: root/pylint
diff options
context:
space:
mode:
authorDaniƫl van Noord <13665637+DanielNoord@users.noreply.github.com>2021-10-31 00:33:23 +0200
committerGitHub <noreply@github.com>2021-10-31 00:33:23 +0200
commit1d3a7ff32b0f6d819b17ce18345502fbc47b48c9 (patch)
treeb3c40c9636f2a816ee61af043700c7c6a1b53a88 /pylint
parent76a7553066130a7dbf4d10922b2530161b2ec5b0 (diff)
downloadpylint-git-1d3a7ff32b0f6d819b17ce18345502fbc47b48c9.tar.gz
Allow no type in Numpy param docstrings for ``mising-param-doc`` (#5231)
This closes #5222 See https://numpydoc.readthedocs.io/en/latest/format.html#parameters for reference
Diffstat (limited to 'pylint')
-rw-r--r--pylint/extensions/_check_docs_utils.py39
1 files changed, 35 insertions, 4 deletions
diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py
index 52f9e470c..92f91847c 100644
--- a/pylint/extensions/_check_docs_utils.py
+++ b/pylint/extensions/_check_docs_utils.py
@@ -23,7 +23,7 @@
"""Utility methods for docstring checking."""
import re
-from typing import List
+from typing import List, Set, Tuple
import astroid
from astroid import nodes
@@ -731,9 +731,8 @@ class NumpyDocstring(GoogleDocstring):
re_param_line = re.compile(
fr"""
- \s* (\*{{0,2}}\w+) # identifier with potential asterisks
- \s* :
- \s* (?:({GoogleDocstring.re_multiple_type})(?:,\s+optional)?)? # optional type declaration
+ \s* (\*{{0,2}}\w+)(\s?(:|\n)) # identifier with potential asterisks
+ \s* (?:({GoogleDocstring.re_multiple_type})(?:,\s+optional)?\n)? # optional type declaration
\s* (.*) # optional description
""",
re.X | re.S,
@@ -772,6 +771,38 @@ class NumpyDocstring(GoogleDocstring):
supports_yields = True
+ def match_param_docs(self) -> Tuple[Set[str], Set[str]]:
+ """Matches parameter documentation section to parameter documentation rules"""
+ params_with_doc = set()
+ params_with_type = set()
+
+ entries = self._parse_section(self.re_param_section)
+ print(entries)
+ entries.extend(self._parse_section(self.re_keyword_param_section))
+ for entry in entries:
+ match = self.re_param_line.match(entry)
+ if not match:
+ continue
+
+ # check if parameter has description only
+ re_only_desc = re.match(r"\s* (\*{0,2}\w+)\s*:?\n", entry)
+ if re_only_desc:
+ param_name = match.group(1)
+ param_desc = match.group(2)
+ param_type = None
+ else:
+ param_name = match.group(1)
+ param_type = match.group(3)
+ param_desc = match.group(4)
+
+ if param_type:
+ params_with_type.add(param_name)
+
+ if param_desc:
+ params_with_doc.add(param_name)
+
+ return params_with_doc, params_with_type
+
@staticmethod
def min_section_indent(section_match):
return len(section_match.group(1))