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 / not_callable.py @ 745
History | View | Annotate | Download (2.19 KB)
1 |
# pylint: disable=missing-docstring,no-self-use,too-few-public-methods
|
---|---|
2 |
|
3 |
REVISION = None
|
4 |
|
5 |
REVISION() # [not-callable]
|
6 |
|
7 |
def correct(): |
8 |
return 1 |
9 |
|
10 |
REVISION = correct() |
11 |
|
12 |
class Correct(object): |
13 |
"""callable object"""
|
14 |
|
15 |
class MetaCorrect(object): |
16 |
"""callable object"""
|
17 |
def __call__(self): |
18 |
return self |
19 |
|
20 |
INSTANCE = Correct() |
21 |
CALLABLE_INSTANCE = MetaCorrect() |
22 |
CORRECT = CALLABLE_INSTANCE() |
23 |
INCORRECT = INSTANCE() # [not-callable]
|
24 |
LIST = [] |
25 |
INCORRECT = LIST() # [not-callable]
|
26 |
DICT = {} |
27 |
INCORRECT = DICT() # [not-callable]
|
28 |
TUPLE = () |
29 |
INCORRECT = TUPLE() # [not-callable]
|
30 |
INT = 1
|
31 |
INCORRECT = INT() # [not-callable]
|
32 |
|
33 |
# Test calling properties. Pylint can detect when using only the
|
34 |
# getter, but it doesn't infer properly when having a getter
|
35 |
# and a setter.
|
36 |
class MyProperty(property): |
37 |
""" test subclasses """
|
38 |
|
39 |
class PropertyTest(object): |
40 |
""" class """
|
41 |
|
42 |
def __init__(self): |
43 |
self.attr = 4 |
44 |
|
45 |
@property
|
46 |
def test(self): |
47 |
""" Get the attribute """
|
48 |
return self.attr |
49 |
|
50 |
@test.setter
|
51 |
def test(self, value): |
52 |
""" Set the attribute """
|
53 |
self.attr = value
|
54 |
|
55 |
@MyProperty
|
56 |
def custom(self): |
57 |
""" Get the attribute """
|
58 |
return self.attr |
59 |
|
60 |
@custom.setter
|
61 |
def custom(self, value): |
62 |
""" Set the attribute """
|
63 |
self.attr = value
|
64 |
|
65 |
PROP = PropertyTest() |
66 |
PROP.test(40) # [not-callable] |
67 |
PROP.custom() # [not-callable]
|
68 |
|
69 |
# Safe from not-callable when using properties.
|
70 |
|
71 |
class SafeProperty(object): |
72 |
@property
|
73 |
def static(self): |
74 |
return staticmethod |
75 |
|
76 |
@property
|
77 |
def klass(self): |
78 |
return classmethod |
79 |
|
80 |
@property
|
81 |
def get_lambda(self): |
82 |
return lambda: None |
83 |
|
84 |
@property
|
85 |
def other_function(self): |
86 |
def function(arg): |
87 |
return arg
|
88 |
return function
|
89 |
|
90 |
@property
|
91 |
def dict_builtin(self): |
92 |
return dict |
93 |
|
94 |
@property
|
95 |
def range_builtin(self): |
96 |
return range |
97 |
|
98 |
@property
|
99 |
def instance(self): |
100 |
class Empty(object): |
101 |
def __call__(self): |
102 |
return 42 |
103 |
return Empty()
|
104 |
|
105 |
PROP1 = SafeProperty() |
106 |
PROP1.static(2)
|
107 |
PROP1.klass(2)
|
108 |
PROP1.get_lambda() |
109 |
PROP1.other_function(4)
|
110 |
PROP1.dict_builtin() |
111 |
PROP1.range_builtin(4)
|
112 |
PROP1.instance() |