diff options
author | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-25 13:44:09 +0200 |
---|---|---|
committer | Pierre Sassoulas <pierre.sassoulas@gmail.com> | 2021-06-25 14:34:48 +0200 |
commit | 14731ad97aa13fd4fc39e0eba134a000bd49b8f5 (patch) | |
tree | 44efd10abc4686eef1b1ee5ab8e9b82b3a22b362 /pylint | |
parent | ce987fdc26bc30611e8e91af1492918175f9af58 (diff) | |
download | pylint-git-14731ad97aa13fd4fc39e0eba134a000bd49b8f5.tar.gz |
Make a smarter check to avoid 'useless-type-doc' false positive
Diffstat (limited to 'pylint')
-rw-r--r-- | pylint/extensions/_check_docs_utils.py | 4 | ||||
-rw-r--r-- | pylint/extensions/docparams.py | 22 |
2 files changed, 11 insertions, 15 deletions
diff --git a/pylint/extensions/_check_docs_utils.py b/pylint/extensions/_check_docs_utils.py index 5f1e8ea0b..de2f427bf 100644 --- a/pylint/extensions/_check_docs_utils.py +++ b/pylint/extensions/_check_docs_utils.py @@ -25,7 +25,6 @@ import re from typing import List import astroid -from astroid import AssignName from pylint.checkers import utils @@ -207,9 +206,6 @@ class Docstring: def __repr__(self) -> str: return f"<{self.__class__.__name__}:'''{self.doc}'''>" - def arg_is_documented(self, arg_name: AssignName) -> bool: - return arg_name.name in self.doc - def is_valid(self): return False diff --git a/pylint/extensions/docparams.py b/pylint/extensions/docparams.py index 032e993a6..42dfd2b87 100644 --- a/pylint/extensions/docparams.py +++ b/pylint/extensions/docparams.py @@ -531,7 +531,6 @@ class DocstringParameterChecker(BaseChecker): expected_argument_names.add(arguments_node.kwarg) not_needed_type_in_docstring.add(arguments_node.kwarg) params_with_doc, params_with_type = doc.match_param_docs() - # Tolerate no parameter documentation at all. if not params_with_doc and not params_with_type and accept_no_param_doc: tolerate_missing_params = True @@ -546,13 +545,20 @@ class DocstringParameterChecker(BaseChecker): warning_node, ) + # This is before the update of param_with_type because this must check only + # the type documented in a docstring, not the one using pep484 + # See #4117 and #4593 + self._compare_ignored_args( + params_with_type, + "useless-type-doc", + expected_but_ignored_argument_names, + warning_node, + ) for index, arg_name in enumerate(arguments_node.args): - if arguments_node.annotations[index] and doc.arg_is_documented(arg_name): + if arguments_node.annotations[index]: params_with_type.add(arg_name.name) for index, arg_name in enumerate(arguments_node.kwonlyargs): - if arguments_node.kwonlyargs_annotations[index] and doc.arg_is_documented( - arg_name - ): + if arguments_node.kwonlyargs_annotations[index]: params_with_type.add(arg_name.name) if not tolerate_missing_params: @@ -584,12 +590,6 @@ class DocstringParameterChecker(BaseChecker): expected_but_ignored_argument_names, warning_node, ) - self._compare_ignored_args( - params_with_type, - "useless-type-doc", - expected_but_ignored_argument_names, - warning_node, - ) def check_single_constructor_params(self, class_doc, init_doc, class_node): if class_doc.has_params() and init_doc.has_params(): |