Debian Codegraph @

test/static_analysis/attribute_error.py

raw symbols SCIP
1 class Cls():
2 class_attr = ''
3 def __init__(self, input):
4 self.instance_attr = 3
5 self.input = input
6
7 def f(self):
8 #! 12 attribute-error
9 return self.not_existing
10
11 def undefined_object(self, obj):
12 """
13 Uses an arbitrary object and performs an operation on it, shouldn't
14 be a problem.
15 """
16 obj.arbitrary_lookup
17
18 def defined_lookup(self, obj):
19 """
20 `obj` is defined by a call into this function.
21 """
22 obj.upper
23 #! 4 attribute-error
24 obj.arbitrary_lookup
25
26 #! 13 name-error
27 class_attr = a
28
29 Cls(1).defined_lookup('')
30
31 c = Cls(1)
32 c.class_attr
33 Cls.class_attr
34 #! 4 attribute-error
35 Cls.class_attr_error
36 c.instance_attr
37 #! 2 attribute-error
38 c.instance_attr_error
39
40
41 c.something = None
42
43 #! 12 name-error
44 something = a
45 something
46
47 # -----------------
48 # Unused array variables should still raise attribute errors.
49 # -----------------
50
51 # should not raise anything.
52 for loop_variable in [1, 2]:
53 #! 4 name-error
54 x = undefined
55 loop_variable
56
57 #! 28 name-error
58 for loop_variable in [1, 2, undefined]:
59 pass
60
61 #! 7 attribute-error
62 [1, ''.undefined_attr]
63
64
65 def return_one(something):
66 return 1
67
68 #! 14 attribute-error
69 return_one(''.undefined_attribute)
70
71 #! 12 name-error
72 [r for r in undefined]
73
74 #! 1 name-error
75 [undefined for r in [1, 2]]
76
77 [r for r in [1, 2]]
78
79 # some random error that showed up
80 class NotCalled():
81 def match_something(self, param):
82 seems_to_need_an_assignment = param
83 return [value.match_something() for value in []]
84
85 # -----------------
86 # decorators
87 # -----------------
88
89 #! 1 name-error
90 @undefined_decorator
91 def func():
92 return 1
93
94 # -----------------
95 # operators
96 # -----------------
97
98 string = '%s %s' % (1, 2)
99
100 # Shouldn't raise an error, because `string` is really just a string, not an
101 # array or something.
102 string.upper
103
104 # -----------------
105 # imports
106 # -----------------
107
108 # Star imports and the like in modules should not cause attribute errors in
109 # this module.
110 import import_tree
111
112 import_tree.a
113 import_tree.b