diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt index e7e73136f7..961f04e813 100644 --- a/CONTRIBUTORS.txt +++ b/CONTRIBUTORS.txt @@ -539,3 +539,7 @@ contributors: * Phil A. (flying-sheep): contributor * Melvin Hazeleger (melvio): contributor + +* Hayden Richards (SupImDos): contributor + - Fixed "no-self-use" for async methods + - Fixed "docparams" extension for async functions and methods diff --git a/ChangeLog b/ChangeLog index 553df04846..0f95359509 100644 --- a/ChangeLog +++ b/ChangeLog @@ -82,6 +82,8 @@ Release date: TBA Closes #1375 +* Fix ``no-self-use`` and ``docparams extension`` for async functions and methods. + What's New in Pylint 2.10.3? ============================ diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py index f924905946..3ce95033eb 100644 --- a/pylint/checkers/classes.py +++ b/pylint/checkers/classes.py @@ -1430,6 +1430,8 @@ def leave_functiondef(self, node: nodes.FunctionDef) -> None: ): self.add_message("no-self-use", node=node) + leave_asyncfunctiondef = leave_functiondef + def visit_attribute(self, node: nodes.Attribute) -> None: """check if the getattr is an access to a class member if so, register it. Also check for access to protected diff --git a/pylint/extensions/docparams.py b/pylint/extensions/docparams.py index bb5ac68057..361a5f28a7 100644 --- a/pylint/extensions/docparams.py +++ b/pylint/extensions/docparams.py @@ -229,6 +229,8 @@ def visit_functiondef(self, node: nodes.FunctionDef) -> None: self.check_functiondef_returns(node, node_doc) self.check_functiondef_yields(node, node_doc) + visit_asyncfunctiondef = visit_functiondef + def check_functiondef_params(self, node, node_doc): node_allow_no_param = None if node.name in self.constructor_names: diff --git a/tests/functional/a/assign/assignment_from_no_return_py3.py b/tests/functional/a/assign/assignment_from_no_return_py3.py index 7b1abd59f9..cb6dcd9623 100644 --- a/tests/functional/a/assign/assignment_from_no_return_py3.py +++ b/tests/functional/a/assign/assignment_from_no_return_py3.py @@ -1,4 +1,4 @@ -# pylint: disable=missing-docstring,too-few-public-methods +# pylint: disable=missing-docstring,too-few-public-methods,no-self-use import asyncio diff --git a/tests/functional/ext/docparams.py b/tests/functional/ext/docparams.py index b879afcfb8..269686a011 100644 --- a/tests/functional/ext/docparams.py +++ b/tests/functional/ext/docparams.py @@ -1,11 +1,41 @@ """Fixture for testing missing documentation in docparams.""" -def _private_func(param1): # [missing-return-doc, missing-return-type-doc] - if param1: - raise Exception('Example') +def _private_func1(param1): # [missing-return-doc, missing-return-type-doc] + """This is a test docstring without returns""" return param1 def _private_func2(param1): # [missing-yield-doc, missing-yield-type-doc] + """This is a test docstring without yields""" yield param1 + + +def _private_func3(param1): # [missing-raises-doc] + """This is a test docstring without raises""" + raise Exception('Example') + + +def public_func1(param1): # [missing-param-doc, missing-type-doc] + """This is a test docstring without params""" + print(param1) + + +async def _async_private_func1(param1): # [missing-return-doc, missing-return-type-doc] + """This is a test docstring without returns""" + return param1 + + +async def _async_private_func2(param1): # [missing-yield-doc, missing-yield-type-doc] + """This is a test docstring without yields""" + yield param1 + + +async def _async_private_func3(param1): # [missing-raises-doc] + """This is a test docstring without raises""" + raise Exception('Example') + + +async def async_public_func1(param1): # [missing-param-doc, missing-type-doc] + """This is a test docstring without params""" + print(param1) diff --git a/tests/functional/ext/docparams.txt b/tests/functional/ext/docparams.txt index 5eb327895c..cccc781268 100644 --- a/tests/functional/ext/docparams.txt +++ b/tests/functional/ext/docparams.txt @@ -1,4 +1,14 @@ -missing-return-doc:4:0:_private_func:Missing return documentation -missing-return-type-doc:4:0:_private_func:Missing return type documentation -missing-yield-doc:10:0:_private_func2:Missing yield documentation -missing-yield-type-doc:10:0:_private_func2:Missing yield type documentation +missing-return-doc:4:0:_private_func1:Missing return documentation +missing-return-type-doc:4:0:_private_func1:Missing return type documentation +missing-yield-doc:9:0:_private_func2:Missing yield documentation +missing-yield-type-doc:9:0:_private_func2:Missing yield type documentation +missing-raises-doc:14:0:_private_func3:"""Exception""" not documented as being raised +missing-param-doc:19:0:public_func1:"""param1""" missing in parameter documentation +missing-type-doc:19:0:public_func1:"""param1""" missing in parameter type documentation +missing-return-doc:24:0:_async_private_func1:Missing return documentation +missing-return-type-doc:24:0:_async_private_func1:Missing return type documentation +missing-yield-doc:29:0:_async_private_func2:Missing yield documentation +missing-yield-type-doc:29:0:_async_private_func2:Missing yield type documentation +missing-raises-doc:34:0:_async_private_func3:"""Exception""" not documented as being raised +missing-param-doc:39:0:async_public_func1:"""param1""" missing in parameter documentation +missing-type-doc:39:0:async_public_func1:"""param1""" missing in parameter type documentation diff --git a/tests/functional/n/no/no_self_use.py b/tests/functional/n/no/no_self_use.py index f84ab15730..8311da0f0e 100644 --- a/tests/functional/n/no/no_self_use.py +++ b/tests/functional/n/no/no_self_use.py @@ -17,6 +17,13 @@ def function_method(self): # [no-self-use] """this method isn' a real method since it doesn't need self""" print('hello') + async def async_regular_method(self): + """this async method is a real method since it accesses self""" + await self.async_function_method() + + async def async_function_method(self): # [no-self-use] + """this async method isn't a real method since it doesn't need self""" + print('hello') class Base(object): """an abstract class""" diff --git a/tests/functional/n/no/no_self_use.txt b/tests/functional/n/no/no_self_use.txt index b14ee9e03c..c91eff9a89 100644 --- a/tests/functional/n/no/no_self_use.txt +++ b/tests/functional/n/no/no_self_use.txt @@ -1 +1,2 @@ no-self-use:16:4:Toto.function_method:Method could be a function +no-self-use:24:4:Toto.async_function_method:Method could be a function