Skip to content

Commit 3aaba09

Browse files
fix(regex): fix re_only_desc and add lookaheads
The `re_only_desc` regex did not match for white and characters after `\n`, so some description-only lines weren't getting matched. In addition, lookaheads were added to `re_param_line` (i.e. make sure the type group is not followed by a new line (`\n`)). Lastly, named groups (ala Perl regular expressions) were added for slightly improved clarity. The hyperlink in the body of test `regression_6211` was causing problems, so this was moved into a reStructuredText directive. Finally, the added `from __future__ import annotations` moved all lines in `tests/functional/ext/docparams/docparams.py` down one line, so the line numbers in `docparams.txt` were off by 1, causing tests to fail. This was corrected.
1 parent b241a92 commit 3aaba09

File tree

3 files changed

+37
-31
lines changed

3 files changed

+37
-31
lines changed

pylint/extensions/_check_docs_utils.py

+15-10
Original file line numberDiff line numberDiff line change
@@ -734,9 +734,10 @@ class NumpyDocstring(GoogleDocstring):
734734

735735
re_param_line = re.compile(
736736
rf"""
737-
\s* (\*{{0,2}}\w+)(\s?(:|\n)) # identifier with potential asterisks
737+
\s* (?P<param_name>\*{{0,2}}\w+)(\s?(:|\n)) # identifier with potential asterisks
738738
\s*
739-
(
739+
(?P<param_type>
740+
(?!=\n)
740741
(
741742
({GoogleDocstring.re_multiple_type}) # default type declaration
742743
(,\s+optional|,\s+{re_default_param})? # optional 'optional' indication
@@ -745,8 +746,11 @@ class NumpyDocstring(GoogleDocstring):
745746
(
746747
{{({re_default_value},?\s*)+}} # set of default values
747748
)?
748-
\n)?
749-
\s* (.*) # optional description
749+
(?:$|\n)
750+
)?
751+
(
752+
\s* (?P<param_desc>.*) # optional description
753+
)?
750754
""",
751755
re.X | re.S,
752756
)
@@ -797,15 +801,16 @@ def match_param_docs(self) -> tuple[set[str], set[str]]:
797801
continue
798802

799803
# check if parameter has description only
800-
re_only_desc = re.match(r"\s* (\*{0,2}\w+)\s*:?\n", entry)
804+
re_only_desc = re.match(r"\s*(\*{0,2}\w+)\s*:?\n\s*\w*$", entry)
805+
print(f're_only_desc: {re_only_desc}')
801806
if re_only_desc:
802-
param_name = match.group(1)
803-
param_desc = match.group(2)
807+
param_name = match.group('param_name')
808+
param_desc = match.group('param_type')
804809
param_type = None
805810
else:
806-
param_name = match.group(1)
807-
param_type = match.group(3)
808-
param_desc = match.group(4)
811+
param_name = match.group('param_name')
812+
param_type = match.group('param_type')
813+
param_desc = match.group('param_desc')
809814

810815
if param_type:
811816
params_with_type.add(param_name)

tests/functional/ext/docparams/docparams.py

+6-5
Original file line numberDiff line numberDiff line change
@@ -116,17 +116,18 @@ def params_with_pipe(arg1: int | bool, arg2: str | None = None) -> None:
116116

117117

118118
def regression_6211(number: int = 0) -> None:
119-
"""This is a regression test for issue #6211.
119+
"""This is a regression test for issue `#6211`_.
120120
121121
False negative of "missing param doc" was being issued when "default" used in
122122
NumPy-style docs. This test should return no errors.
123123
124-
See https://github.com/PyCQA/pylint/issues/6211
125-
126-
Parameter
127-
---------
124+
Parameters
125+
----------
128126
number : int, default 0
129127
The number parameter
128+
129+
.. _`#6211`:
130+
https://github.com/PyCQA/pylint/issues/6211
130131
"""
131132

132133
print(number)
+16-16
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,16 @@
1-
missing-return-doc:4:0:4:18:_private_func1:Missing return documentation:HIGH
2-
missing-return-type-doc:4:0:4:18:_private_func1:Missing return type documentation:HIGH
3-
missing-yield-doc:9:0:9:18:_private_func2:Missing yield documentation:HIGH
4-
missing-yield-type-doc:9:0:9:18:_private_func2:Missing yield type documentation:HIGH
5-
missing-raises-doc:14:0:14:18:_private_func3:"""Exception"" not documented as being raised":HIGH
6-
missing-any-param-doc:19:0:19:16:public_func1:"Missing any documentation in ""public_func1""":HIGH
7-
missing-return-doc:24:0:24:30:_async_private_func1:Missing return documentation:HIGH
8-
missing-return-type-doc:24:0:24:30:_async_private_func1:Missing return type documentation:HIGH
9-
missing-yield-doc:29:0:29:30:_async_private_func2:Missing yield documentation:HIGH
10-
missing-yield-type-doc:29:0:29:30:_async_private_func2:Missing yield type documentation:HIGH
11-
missing-raises-doc:34:0:34:30:_async_private_func3:"""Exception"" not documented as being raised":HIGH
12-
missing-any-param-doc:39:0:39:28:async_public_func1:"Missing any documentation in ""async_public_func1""":HIGH
13-
differing-param-doc:44:0:44:23:differing_param_doc:"""param"" differing in parameter documentation":HIGH
14-
differing-param-doc:55:0:55:35:differing_param_doc_kwords_only:"""param"" differing in parameter documentation":HIGH
15-
missing-type-doc:66:0:66:20:missing_type_doc:"""par1"" missing in parameter type documentation":HIGH
16-
missing-type-doc:76:0:76:32:missing_type_doc_kwords_only:"""par1"" missing in parameter type documentation":HIGH
1+
missing-return-doc:5:0:5:18:_private_func1:Missing return documentation:HIGH
2+
missing-return-type-doc:5:0:5:18:_private_func1:Missing return type documentation:HIGH
3+
missing-yield-doc:10:0:10:18:_private_func2:Missing yield documentation:HIGH
4+
missing-yield-type-doc:10:0:10:18:_private_func2:Missing yield type documentation:HIGH
5+
missing-raises-doc:15:0:15:18:_private_func3:"""Exception"" not documented as being raised":HIGH
6+
missing-any-param-doc:20:0:20:16:public_func1:"Missing any documentation in ""public_func1""":HIGH
7+
missing-return-doc:25:0:25:30:_async_private_func1:Missing return documentation:HIGH
8+
missing-return-type-doc:25:0:25:30:_async_private_func1:Missing return type documentation:HIGH
9+
missing-yield-doc:30:0:30:30:_async_private_func2:Missing yield documentation:HIGH
10+
missing-yield-type-doc:30:0:30:30:_async_private_func2:Missing yield type documentation:HIGH
11+
missing-raises-doc:35:0:35:30:_async_private_func3:"""Exception"" not documented as being raised":HIGH
12+
missing-any-param-doc:40:0:40:28:async_public_func1:"Missing any documentation in ""async_public_func1""":HIGH
13+
differing-param-doc:45:0:45:23:differing_param_doc:"""param"" differing in parameter documentation":HIGH
14+
differing-param-doc:56:0:56:35:differing_param_doc_kwords_only:"""param"" differing in parameter documentation":HIGH
15+
missing-type-doc:67:0:67:20:missing_type_doc:"""par1"" missing in parameter type documentation":HIGH
16+
missing-type-doc:77:0:77:32:missing_type_doc_kwords_only:"""par1"" missing in parameter type documentation":HIGH

0 commit comments

Comments
 (0)