Skip to content

Commit

Permalink
Merge branch 'main' into global-variable
Browse files Browse the repository at this point in the history
  • Loading branch information
Pierre-Sassoulas committed Sep 11, 2021
2 parents b2746d5 + 7390b6f commit 796a696
Show file tree
Hide file tree
Showing 9 changed files with 66 additions and 8 deletions.
4 changes: 4 additions & 0 deletions CONTRIBUTORS.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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
2 changes: 2 additions & 0 deletions ChangeLog
Original file line number Diff line number Diff line change
Expand Up @@ -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?
============================
Expand Down
2 changes: 2 additions & 0 deletions pylint/checkers/classes.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions pylint/extensions/docparams.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion tests/functional/a/assign/assignment_from_no_return_py3.py
Original file line number Diff line number Diff line change
@@ -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

Expand Down
36 changes: 33 additions & 3 deletions tests/functional/ext/docparams.py
Original file line number Diff line number Diff line change
@@ -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)
18 changes: 14 additions & 4 deletions tests/functional/ext/docparams.txt
Original file line number Diff line number Diff line change
@@ -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
7 changes: 7 additions & 0 deletions tests/functional/n/no/no_self_use.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"""
Expand Down
1 change: 1 addition & 0 deletions tests/functional/n/no/no_self_use.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit 796a696

Please sign in to comment.