summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLaura M?dioni <laura.medioni@logilab.fr>2015-10-29 15:30:59 +0100
committerLaura M?dioni <laura.medioni@logilab.fr>2015-10-29 15:30:59 +0100
commitac584cb0f525d5ba86e06925077eb82d270b8a39 (patch)
treebe83fc0ff1629d24bc0affa49553d421e2223810
parentdd419712a064c2ec25839492e8c3b2acccbd76a3 (diff)
downloadpylint-ac584cb0f525d5ba86e06925077eb82d270b8a39.tar.gz
no-static/class-method: enhance the tests and fix the code accordingly
-rw-r--r--pylint/checkers/classes.py7
-rw-r--r--pylint/test/functional/no_classmethod_decorator.py11
-rw-r--r--pylint/test/functional/no_classmethod_decorator.txt2
-rw-r--r--pylint/test/functional/no_staticmethod_decorator.py9
-rw-r--r--pylint/test/functional/no_staticmethod_decorator.txt2
5 files changed, 24 insertions, 7 deletions
diff --git a/pylint/checkers/classes.py b/pylint/checkers/classes.py
index d12f45d..014dd4a 100644
--- a/pylint/checkers/classes.py
+++ b/pylint/checkers/classes.py
@@ -651,7 +651,7 @@ a metaclass class method.'}
msg = ('no-classmethod-decorator' if func.name == 'classmethod' else
'no-staticmethod-decorator')
# assignment must be at a class scope
- parent_class = node.parent
+ parent_class = node.scope()
if not isinstance(parent_class, astroid.ClassDef):
return
# Check if the arg passed to classmethod is a class member
@@ -659,9 +659,8 @@ a metaclass class method.'}
if not isinstance(classmeth_arg, astroid.Name):
return
method_name = classmeth_arg.name
- for member in parent_class.get_children():
- if (isinstance(member, astroid.FunctionDef) and
- method_name == member.name):
+ for member in parent_class.mymethods():
+ if method_name == member.name:
self.add_message(msg, node=node.targets[0])
break
diff --git a/pylint/test/functional/no_classmethod_decorator.py b/pylint/test/functional/no_classmethod_decorator.py
index f44dca5..2f91fde 100644
--- a/pylint/test/functional/no_classmethod_decorator.py
+++ b/pylint/test/functional/no_classmethod_decorator.py
@@ -2,7 +2,7 @@
scope and if classmethod's argument is a member of the class
"""
-# pylint: disable=too-few-public-methods
+# pylint: disable=too-few-public-methods, using-constant-test, no-self-argument
class MyClass(object):
"""Some class"""
@@ -11,12 +11,19 @@ class MyClass(object):
def cmethod(cls):
"""class method-to-be"""
- cmethod = classmethod(cmethod) # [no-classmethod-decorator]
+ cmethod = classmethod(cmethod) # [no-classmethod-decorator]
+
+ if True:
+ cmethod = classmethod(cmethod) # [no-classmethod-decorator]
@classmethod
def my_second_method(cls):
"""correct class method definition"""
+ def other_method(cls):
+ """some method"""
+ cmethod2 = classmethod(other_method) # [no-classmethod-decorator]
+
def helloworld():
"""says hello"""
print 'hello world'
diff --git a/pylint/test/functional/no_classmethod_decorator.txt b/pylint/test/functional/no_classmethod_decorator.txt
index 8c1060f..ba51f0b 100644
--- a/pylint/test/functional/no_classmethod_decorator.txt
+++ b/pylint/test/functional/no_classmethod_decorator.txt
@@ -1 +1,3 @@
no-classmethod-decorator:14:MyClass:Consider using a decorator instead of calling classmethod
+no-classmethod-decorator:17:MyClass:Consider using a decorator instead of calling classmethod
+no-classmethod-decorator:25:MyClass:Consider using a decorator instead of calling classmethod
diff --git a/pylint/test/functional/no_staticmethod_decorator.py b/pylint/test/functional/no_staticmethod_decorator.py
index 9e26454..a64cd7c 100644
--- a/pylint/test/functional/no_staticmethod_decorator.py
+++ b/pylint/test/functional/no_staticmethod_decorator.py
@@ -2,7 +2,7 @@
scope and if static method's argument is a member of the class
"""
-# pylint: disable=too-few-public-methods
+# pylint: disable=too-few-public-methods, using-constant-test, no-method-argument
class MyClass(object):
"""Some class"""
@@ -13,10 +13,17 @@ class MyClass(object):
"""static method-to-be"""
smethod = staticmethod(smethod) # [no-staticmethod-decorator]
+ if True:
+ smethod = staticmethod(smethod) # [no-staticmethod-decorator]
+
@staticmethod
def my_second_method():
"""correct static method definition"""
+ def other_method():
+ """some method"""
+ smethod2 = staticmethod(other_method) # [no-staticmethod-decorator]
+
def helloworld():
"""says hello"""
print 'hello world'
diff --git a/pylint/test/functional/no_staticmethod_decorator.txt b/pylint/test/functional/no_staticmethod_decorator.txt
index b8d23ae..c0aea0e 100644
--- a/pylint/test/functional/no_staticmethod_decorator.txt
+++ b/pylint/test/functional/no_staticmethod_decorator.txt
@@ -1 +1,3 @@
no-staticmethod-decorator:14:MyClass:Consider using a decorator instead of calling staticmethod
+no-staticmethod-decorator:17:MyClass:Consider using a decorator instead of calling staticmethod
+no-staticmethod-decorator:25:MyClass:Consider using a decorator instead of calling staticmethod