blob: 65e12fa7e389e9ff50f00c7a0b50eb109dd38ed6 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
|
# pylint: disable=R0903,W0232,missing-docstring
"""test detection of method which could be a function"""
from __future__ import print_function
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')
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 concret class"""
def check(self, arg):
"""a concret 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"""
print(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
|