gvsig-scripting / org.gvsig.scripting / trunk / org.gvsig.scripting / org.gvsig.scripting.app / org.gvsig.scripting.app.mainplugin / src / main / resources-plugin / scripting / lib / pylint / test / functional / no_self_use.py @ 745
History | View | Annotate | Download (1.67 KB)
1 |
# pylint: disable=R0903,W0232,missing-docstring
|
---|---|
2 |
"""test detection of method which could be a function"""
|
3 |
|
4 |
from __future__ import print_function |
5 |
|
6 |
class Toto(object): |
7 |
"""bla bal abl"""
|
8 |
|
9 |
def __init__(self): |
10 |
self.aaa = 2 |
11 |
|
12 |
def regular_method(self): |
13 |
"""this method is a real method since it access to self"""
|
14 |
self.function_method()
|
15 |
|
16 |
def function_method(self): # [no-self-use] |
17 |
"""this method isn' a real method since it doesn't need self"""
|
18 |
print('hello')
|
19 |
|
20 |
|
21 |
class Base(object): |
22 |
"""an abstract class"""
|
23 |
|
24 |
def __init__(self): |
25 |
self.aaa = 2 |
26 |
|
27 |
def check(self, arg): |
28 |
"""an abstract method, could not be a function"""
|
29 |
raise NotImplementedError |
30 |
|
31 |
|
32 |
class Sub(Base): |
33 |
"""a concret class"""
|
34 |
|
35 |
def check(self, arg): |
36 |
"""a concret method, could not be a function since it need
|
37 |
polymorphism benefits
|
38 |
"""
|
39 |
return arg == 0 |
40 |
|
41 |
class Super(object): |
42 |
"""same as before without abstract"""
|
43 |
attr = 1
|
44 |
def method(self): |
45 |
"""regular"""
|
46 |
print(self.attr)
|
47 |
|
48 |
class Sub1(Super): |
49 |
"""override method with need for self"""
|
50 |
def method(self): |
51 |
"""no i can not be a function"""
|
52 |
print(42)
|
53 |
|
54 |
def __len__(self): |
55 |
"""no i can not be a function"""
|
56 |
print(42)
|
57 |
|
58 |
def __cmp__(self, other): |
59 |
"""no i can not be a function"""
|
60 |
print(42)
|
61 |
|
62 |
def __copy__(self): |
63 |
return 24 |
64 |
|
65 |
def __getstate__(self): |
66 |
return 42 |
67 |
|
68 |
|
69 |
class Prop(object): |
70 |
|
71 |
@property
|
72 |
def count(self): |
73 |
"""Don't emit no-self-use for properties.
|
74 |
|
75 |
They can't be functions and they can be part of an
|
76 |
API specification.
|
77 |
"""
|
78 |
return 42 |