Skip to content

Commit c159024

Browse files
Fix differing param doc false positive (#6980)
* Read `posonly` args and annotations on `check_arguments_in_docstring` Co-authored-by: Pierre Sassoulas <[email protected]>
1 parent 680edeb commit c159024

File tree

7 files changed

+111
-0
lines changed

7 files changed

+111
-0
lines changed

doc/whatsnew/2/2.14/full.rst

+3
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ What's New in Pylint 2.14.4?
55
----------------------------
66
Release date: TBA
77

8+
* The ``differing-param-doc`` check was triggered by positional only arguments.
9+
10+
Closes #6950
811

912

1013
What's New in Pylint 2.14.3?

pylint/extensions/docparams.py

+4
Original file line numberDiff line numberDiff line change
@@ -524,6 +524,7 @@ class constructor.
524524
# Collect the function arguments.
525525
expected_argument_names = {arg.name for arg in arguments_node.args}
526526
expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
527+
expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
527528
not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()
528529

529530
expected_but_ignored_argument_names = set()
@@ -561,6 +562,9 @@ class constructor.
561562
for index, arg_name in enumerate(arguments_node.kwonlyargs):
562563
if arguments_node.kwonlyargs_annotations[index]:
563564
params_with_type.add(arg_name.name)
565+
for index, arg_name in enumerate(arguments_node.posonlyargs):
566+
if arguments_node.posonlyargs_annotations[index]:
567+
params_with_type.add(arg_name.name)
564568

565569
if not tolerate_missing_params:
566570
missing_param_doc = (expected_argument_names - params_with_doc) - (

tests/functional/ext/docparams/docparams.py

+53
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,56 @@ async def _async_private_func3(param1): # [missing-raises-doc]
3939
async def async_public_func1(param1): # [missing-any-param-doc]
4040
"""This is a test docstring without params"""
4141
print(param1)
42+
43+
44+
def differing_param_doc(par1: int) -> int: # [differing-param-doc]
45+
"""This is a test docstring documenting one non-existing param
46+
47+
:param par1: some param
48+
:param param: some param
49+
:return: the sum of the params
50+
"""
51+
52+
return par1
53+
54+
55+
def differing_param_doc_kwords_only(*, par1: int) -> int: # [differing-param-doc]
56+
"""This is a test docstring documenting one non-existing param
57+
58+
:param par1: some param
59+
:param param: some param
60+
:return: the sum of the params
61+
"""
62+
63+
return par1
64+
65+
66+
def missing_type_doc(par1) -> int: # [missing-type-doc]
67+
"""This is a test docstring params where the type is not specified
68+
69+
:param par1: some param
70+
:return: the param
71+
"""
72+
73+
return par1
74+
75+
76+
def missing_type_doc_kwords_only(*, par1) -> int: # [missing-type-doc]
77+
"""This is a test docstring params where the type is not specified
78+
79+
:param par1: some param
80+
:return: the param
81+
"""
82+
83+
return par1
84+
85+
86+
def params_are_documented(par1: int, *, par2: int) -> int:
87+
"""This is a test docstring params where nothing is raised as it is all documented
88+
89+
:param par1: some param
90+
:param par2: some other param
91+
:return: the sum of params
92+
"""
93+
94+
return par1 + par2

tests/functional/ext/docparams/docparams.txt

+4
Original file line numberDiff line numberDiff line change
@@ -10,3 +10,7 @@ missing-yield-doc:29:0:29:30:_async_private_func2:Missing yield documentation:UN
1010
missing-yield-type-doc:29:0:29:30:_async_private_func2:Missing yield type documentation:UNDEFINED
1111
missing-raises-doc:34:0:34:30:_async_private_func3:"""Exception"" not documented as being raised":UNDEFINED
1212
missing-any-param-doc:39:0:39:28:async_public_func1:"Missing any documentation in ""async_public_func1""":UNDEFINED
13+
differing-param-doc:44:0:44:23:differing_param_doc:"""param"" differing in parameter documentation":UNDEFINED
14+
differing-param-doc:55:0:55:35:differing_param_doc_kwords_only:"""param"" differing in parameter documentation":UNDEFINED
15+
missing-type-doc:66:0:66:20:missing_type_doc:"""par1"" missing in parameter type documentation":UNDEFINED
16+
missing-type-doc:76:0:76:32:missing_type_doc_kwords_only:"""par1"" missing in parameter type documentation":UNDEFINED
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
"""Fixture for testing missing documentation in docparams (Python >=3.8 only)."""
2+
3+
4+
def differing_param_doc_pos_only(par1: int, /) -> int: # [differing-param-doc]
5+
"""This is a test docstring documenting one non-existing param
6+
7+
:param par1: some param
8+
:param param: some param
9+
:return: the sum of the params
10+
"""
11+
12+
return par1
13+
14+
15+
def missing_type_doc_pos_only(par1, /) -> int: # [missing-type-doc]
16+
"""This is a test docstring params where the type is not specified
17+
18+
:param par1: some param
19+
:return: the param
20+
"""
21+
22+
return par1
23+
24+
25+
def params_are_documented(par1: int, /, par2: int, *, par3: int) -> int:
26+
"""This is a test docstring params where nothing is raised as it is all documented
27+
28+
:param par1: some param
29+
:param par2: some other param
30+
:param par3: some other param
31+
:return: the sum of params
32+
"""
33+
34+
return par1 + par2 + par3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
[MAIN]
2+
load-plugins = pylint.extensions.docparams
3+
4+
[BASIC]
5+
accept-no-param-doc = no
6+
accept-no-raise-doc = no
7+
accept-no-return-doc = no
8+
accept-no-yields-doc = no
9+
10+
[testoptions]
11+
min_pyver=3.8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
differing-param-doc:4:0:4:32:differing_param_doc_pos_only:"""param"" differing in parameter documentation":UNDEFINED
2+
missing-type-doc:15:0:15:29:missing_type_doc_pos_only:"""par1"" missing in parameter type documentation":UNDEFINED

0 commit comments

Comments
 (0)