summaryrefslogtreecommitdiff
path: root/tests/functional/ext
diff options
context:
space:
mode:
authorMarc Mueller <30130371+cdce8p@users.noreply.github.com>2022-05-05 18:47:47 +0200
committerGitHub <noreply@github.com>2022-05-05 18:47:47 +0200
commit66fcbeb9fc088f4c88a007cb87e590b6765b2391 (patch)
tree472a7881101f5d0a8e4c9385b983bf3d3dd678f4 /tests/functional/ext
parent04d54f3d179d378076e9dd465cbd8a35a32d659b (diff)
downloadpylint-git-66fcbeb9fc088f4c88a007cb87e590b6765b2391.tar.gz
Move no-self-use to optional extension (#6448)
Co-authored-by: Pierre Sassoulas <pierre.sassoulas@gmail.com>
Diffstat (limited to 'tests/functional/ext')
-rw-r--r--tests/functional/ext/docparams/parameter/missing_param_doc_required_Sphinx.py2
-rw-r--r--tests/functional/ext/docparams/return/missing_return_doc_required_Sphinx.py2
-rw-r--r--tests/functional/ext/mccabe/mccabe.py2
-rw-r--r--tests/functional/ext/no_self_use/no_self_use.py164
-rw-r--r--tests/functional/ext/no_self_use/no_self_use.rc5
-rw-r--r--tests/functional/ext/no_self_use/no_self_use.txt3
6 files changed, 175 insertions, 3 deletions
diff --git a/tests/functional/ext/docparams/parameter/missing_param_doc_required_Sphinx.py b/tests/functional/ext/docparams/parameter/missing_param_doc_required_Sphinx.py
index b1028c749..a2a2f7c92 100644
--- a/tests/functional/ext/docparams/parameter/missing_param_doc_required_Sphinx.py
+++ b/tests/functional/ext/docparams/parameter/missing_param_doc_required_Sphinx.py
@@ -2,7 +2,7 @@
with accept-no-param-doc = no"""
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-class-docstring
# pylint: disable=unused-argument, too-few-public-methods, unnecessary-pass, line-too-long
-# pylint: disable=missing-function-docstring, disallowed-name, no-self-use
+# pylint: disable=missing-function-docstring, disallowed-name
def test_missing_func_params_in_sphinx_docstring( # [missing-param-doc, missing-type-doc]
diff --git a/tests/functional/ext/docparams/return/missing_return_doc_required_Sphinx.py b/tests/functional/ext/docparams/return/missing_return_doc_required_Sphinx.py
index 50ae7033b..8f3d3333b 100644
--- a/tests/functional/ext/docparams/return/missing_return_doc_required_Sphinx.py
+++ b/tests/functional/ext/docparams/return/missing_return_doc_required_Sphinx.py
@@ -2,7 +2,7 @@
with accept-no-returns-doc = no"""
# pylint: disable=function-redefined, invalid-name, undefined-variable, missing-function-docstring
# pylint: disable=unused-argument, disallowed-name, too-few-public-methods
-# pylint: disable=no-self-use, line-too-long
+# pylint: disable=line-too-long
def my_func(self): # [missing-return-type-doc]
diff --git a/tests/functional/ext/mccabe/mccabe.py b/tests/functional/ext/mccabe/mccabe.py
index b5a257b1f..e57d13e2e 100644
--- a/tests/functional/ext/mccabe/mccabe.py
+++ b/tests/functional/ext/mccabe/mccabe.py
@@ -1,7 +1,7 @@
# pylint: disable=invalid-name,unnecessary-pass,no-else-return,useless-else-on-loop
# pylint: disable=undefined-variable,consider-using-sys-exit,unused-variable,too-many-return-statements
# pylint: disable=redefined-outer-name,useless-object-inheritance,using-constant-test,unused-argument
-# pylint: disable=broad-except, not-context-manager, no-method-argument, no-self-use, unspecified-encoding
+# pylint: disable=broad-except, not-context-manager, no-method-argument, unspecified-encoding
"""Checks use of "too-complex" check"""
diff --git a/tests/functional/ext/no_self_use/no_self_use.py b/tests/functional/ext/no_self_use/no_self_use.py
new file mode 100644
index 000000000..dfe3f6f35
--- /dev/null
+++ b/tests/functional/ext/no_self_use/no_self_use.py
@@ -0,0 +1,164 @@
+# pylint: disable=too-few-public-methods,missing-docstring,useless-object-inheritance,invalid-name
+"""test detection of method which could be a function"""
+from abc import ABC, abstractmethod
+from typing import Protocol, overload
+
+
+class Toto(object):
+ """bla bal abl"""
+
+ def __init__(self):
+ self.aaa = 2
+
+ def regular_method(self):
+ """this method is a real method since it access to self"""
+ self.function_method()
+
+ 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"""
+
+ def __init__(self):
+ self.aaa = 2
+
+ def check(self, arg):
+ """an abstract method, could not be a function"""
+ raise NotImplementedError
+
+
+class Sub(Base):
+ """a concrete class"""
+
+ def check(self, arg):
+ """a concrete method, could not be a function since it need
+ polymorphism benefits
+ """
+ return arg == 0
+
+class Super(object):
+ """same as before without abstract"""
+ attr = 1
+ def method(self):
+ """regular"""
+ print(self.attr)
+
+class Sub1(Super):
+ """override method with need for self"""
+ def method(self):
+ """no i can not be a function"""
+ print(42)
+
+ def __len__(self):
+ """no i can not be a function"""
+ return 42
+
+ def __cmp__(self, other):
+ """no i can not be a function"""
+ print(42)
+
+ def __copy__(self):
+ return 24
+
+ def __getstate__(self):
+ return 42
+
+
+class Prop(object):
+
+ @property
+ def count(self):
+ """Don't emit no-self-use for properties.
+
+ They can't be functions and they can be part of an
+ API specification.
+ """
+ return 42
+
+
+class A:
+ def __init__(self):
+ self.store = {}
+
+ def get(self, key, default=None):
+ return self.store.get(key, default)
+
+class B(A):
+ def get_memo(self, obj):
+ return super().get(obj)
+
+
+class C:
+ def a(self, /): # [no-self-use]
+ ...
+
+ # Disable with old error code
+ # pylint: disable=use-symbolic-message-instead
+ def b(self, /): # pylint: disable=R0201
+ ...
+
+
+def func_a(self): # pylint: disable=unused-argument
+ pass
+
+
+class Foo1(ABC):
+ """Don't emit no-self-use for abstract methods."""
+
+ @abstractmethod
+ def a(self):
+ pass
+
+ def b(self):
+ raise NotImplementedError
+
+ def c(self):
+ pass # pass counts as abstract
+
+
+class Foo2(Protocol):
+ """Don't emit no-self-use for methods in Protocol classes."""
+
+ def a(self):
+ ...
+
+class Foo3:
+ """Don't emit no-self-use for overload methods."""
+
+ @overload
+ def a(self, var): ...
+
+ @overload
+ def a(self, var): ...
+
+ def a(self, var):
+ pass
+
+
+class Foo4:
+ """Other false positive cases."""
+
+ @staticmethod
+ def a(self): # pylint: disable=unused-argument,bad-staticmethod-argument
+ ...
+
+ @staticmethod
+ def b():
+ ...
+
+ @classmethod
+ def c(self): # pylint: disable=bad-classmethod-argument
+ ...
+
+ def d(): # pylint: disable=no-method-argument
+ ...
diff --git a/tests/functional/ext/no_self_use/no_self_use.rc b/tests/functional/ext/no_self_use/no_self_use.rc
new file mode 100644
index 000000000..3f87505dd
--- /dev/null
+++ b/tests/functional/ext/no_self_use/no_self_use.rc
@@ -0,0 +1,5 @@
+[master]
+load-plugins=pylint.extensions.no_self_use
+
+[testoptions]
+min_pyver=3.8
diff --git a/tests/functional/ext/no_self_use/no_self_use.txt b/tests/functional/ext/no_self_use/no_self_use.txt
new file mode 100644
index 000000000..921c2030d
--- /dev/null
+++ b/tests/functional/ext/no_self_use/no_self_use.txt
@@ -0,0 +1,3 @@
+no-self-use:17:4:17:23:Toto.function_method:Method could be a function:HIGH
+no-self-use:25:4:25:35:Toto.async_function_method:Method could be a function:HIGH
+no-self-use:102:4:102:9:C.a:Method could be a function:HIGH