Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix differing param doc false positive #6980

3 changes: 3 additions & 0 deletions doc/whatsnew/2/2.15/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,9 @@ Extensions
False positives fixed
=====================

* The ``differing-param-doc`` check was triggered by positional only arguments.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Pierre-Sassoulas I didn't notice this, but the changelog entry is in the wrong place. Should be 2.14.4.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm going to fix in the maintenance branch at release time.


Closes #6950

False negatives fixed
=====================
Expand Down
4 changes: 4 additions & 0 deletions pylint/extensions/docparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -525,6 +525,7 @@ class constructor.
# Collect the function arguments.
expected_argument_names = {arg.name for arg in arguments_node.args}
expected_argument_names.update(arg.name for arg in arguments_node.kwonlyargs)
expected_argument_names.update(arg.name for arg in arguments_node.posonlyargs)
not_needed_type_in_docstring = self.not_needed_param_in_docstring.copy()

expected_but_ignored_argument_names = set()
Expand Down Expand Up @@ -562,6 +563,9 @@ class constructor.
for index, arg_name in enumerate(arguments_node.kwonlyargs):
if arguments_node.kwonlyargs_annotations[index]:
params_with_type.add(arg_name.name)
for index, arg_name in enumerate(arguments_node.posonlyargs):
if arguments_node.posonlyargs_annotations[index]:
params_with_type.add(arg_name.name)

if not tolerate_missing_params:
missing_param_doc = (expected_argument_names - params_with_doc) - (
Expand Down
63 changes: 63 additions & 0 deletions tests/functional/ext/docparams/docparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,66 @@ async def _async_private_func3(param1): # [missing-raises-doc]
async def async_public_func1(param1): # [missing-any-param-doc]
"""This is a test docstring without params"""
print(param1)


def differing_param_doc(par1: int) -> int: # [differing-param-doc]
"""This is a test docstring documenting one non-existing param

:param par1: some param
:param param: some param
:return: the sum of the params
"""

return par1


def differing_param_doc_kwords_only(*, par1: int) -> int: # [differing-param-doc]
"""This is a test docstring documenting one non-existing param

:param par1: some param
:param param: some param
:return: the sum of the params
"""

return par1


def differing_param_doc_pos_only(par1: int, /) -> int: # [differing-param-doc]
"""This is a test docstring documenting one non-existing param

:param par1: some param
:param param: some param
:return: the sum of the params
"""

return par1


def missing_type_doc(par1) -> int: # [missing-type-doc]
"""This is a test docstring params where the type is not specified

:param par1: some param
:return: the param
"""

return par1


def missing_type_doc_kwords_only(*, par1) -> int: # [missing-type-doc]
"""This is a test docstring params where the type is not specified

:param par1: some param
:return: the param
"""

return par1
mpernigo marked this conversation as resolved.
Show resolved Hide resolved


def missing_type_doc_pos_only(par1, /) -> int: # [missing-type-doc]
"""This is a test docstring params where the type is not specified

:param par1: some param
:return: the param
"""

return par1
6 changes: 6 additions & 0 deletions tests/functional/ext/docparams/docparams.txt
Original file line number Diff line number Diff line change
Expand Up @@ -10,3 +10,9 @@ missing-yield-doc:29:0:29:30:_async_private_func2:Missing yield documentation:UN
missing-yield-type-doc:29:0:29:30:_async_private_func2:Missing yield type documentation:UNDEFINED
missing-raises-doc:34:0:34:30:_async_private_func3:"""Exception"" not documented as being raised":UNDEFINED
missing-any-param-doc:39:0:39:28:async_public_func1:"Missing any documentation in ""async_public_func1""":UNDEFINED
differing-param-doc:44:0:44:23:differing_param_doc:"""param"" differing in parameter documentation":UNDEFINED
differing-param-doc:55:0:55:35:differing_param_doc_kwords_only:"""param"" differing in parameter documentation":UNDEFINED
differing-param-doc:66:0:66:32:differing_param_doc_pos_only:"""param"" differing in parameter documentation":UNDEFINED
missing-type-doc:77:0:77:20:missing_type_doc:"""par1"" missing in parameter type documentation":UNDEFINED
missing-type-doc:87:0:87:32:missing_type_doc_kwords_only:"""par1"" missing in parameter type documentation":UNDEFINED
missing-type-doc:97:0:97:29:missing_type_doc_pos_only:"""par1"" missing in parameter type documentation":UNDEFINED