aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSupImDos <62866982+SupImDos@users.noreply.github.com>2021-09-11 13:31:12 +0800
committerGitHub <noreply@github.com>2021-09-11 07:31:12 +0200
commit7390b6fd0b2f80a1d3dc09327f959bffff5a94b0 (patch)
treea13119add3f3ff55588b2b0c6d0a6a29812a54ae
parente777697819319200a6956e142405a0499995a2cb (diff)
downloadpylint-7390b6fd0b2f80a1d3dc09327f959bffff5a94b0.tar.gz
Fix no-self-use and docparams extension for async functions/methods (#4986)
* Fixed 'no-self-check' for async functions. * fixed 'docparams' for async functions. * Added 'no-self-use' to the pylint disable comment in broken test. * Added small changelog entry to Pylint 2.11.0 milestone. * Added test: 'no-self-use' for async method. * Added test: revamped 'docparams' functional tests to test all missing documentation. Co-authored-by: Marc Mueller <30130371+cdce8p@users.noreply.github.com> Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
-rw-r--r--CONTRIBUTORS.txt4
-rw-r--r--ChangeLog2
-rw-r--r--pylint/checkers/classes.py2
-rw-r--r--pylint/extensions/docparams.py2
-rw-r--r--tests/functional/a/assign/assignment_from_no_return_py3.py2
-rw-r--r--tests/functional/ext/docparams.py36
-rw-r--r--tests/functional/ext/docparams.txt18
-rw-r--r--tests/functional/n/no/no_self_use.py7
-rw-r--r--tests/functional/n/no/no_self_use.txt1
9 files changed, 66 insertions, 8 deletions
diff --git a/CONTRIBUTORS.txt b/CONTRIBUTORS.txt
index e7e73136f..961f04e81 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 0ab7ee69d..0fffa5a0f 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -77,6 +77,8 @@ Release date: TBA
Closes #4900
+* 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 f92490594..3ce95033e 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -1430,6 +1430,8 @@ a metaclass class method.",
):
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 bb5ac6805..361a5f28a 100644
--- a/pylint/extensions/docparams.py
+++ b/pylint/extensions/docparams.py
@@ -229,6 +229,8 @@ class DocstringParameterChecker(BaseChecker):
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 7b1abd59f..cb6dcd962 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 b879afcfb..269686a01 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 5eb327895..cccc78126 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 f84ab1573..8311da0f0 100644
--- a/tests/functional/n/no/no_self_use.py
+++ b/tests/functional/n/no/no_self_use.py
@@ -17,6 +17,13 @@ class Toto(object):
"""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 b14ee9e03..c91eff9a8 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