Debian Codegraph @

test/completion/flow_analysis.py

raw symbols SCIP
1 # -----------------
2 # First a few name resolution things
3 # -----------------
4
5 x = 3
6 if NOT_DEFINED:
7 x = ''
8 #? 6 int()
9 elif x:
10 pass
11 else:
12 #? int()
13 x
14
15 x = 1
16 try:
17 x = ''
18 #? 8 int() str()
19 except x:
20 #? 5 int() str()
21 x
22 x = 1.0
23 else:
24 #? 5 int() str()
25 x
26 x = list
27 finally:
28 #? 5 int() str() float() list
29 x
30 x = tuple
31
32 if False:
33 with open("") as defined_in_false:
34 #? ['flush']
35 defined_in_false.flu
36
37 # -----------------
38 # Return checks
39 # -----------------
40
41 def foo(x):
42 if 1.0:
43 return 1
44 else:
45 return ''
46
47 #? int()
48 foo(1)
49
50
51 # Exceptions are not analyzed. So check both if branches
52 def try_except(x):
53 try:
54 if 0:
55 return 1
56 else:
57 return ''
58 except AttributeError:
59 return 1.0
60
61 #? float() str()
62 try_except(1)
63
64
65 # Exceptions are not analyzed. So check both if branches
66 def try_except(x):
67 try:
68 if 0:
69 return 1
70 else:
71 return ''
72 except AttributeError:
73 return 1.0
74
75 #? float() str()
76 try_except(1)
77
78 def test_function():
79 a = int(input())
80 if a % 2 == 0:
81 return True
82 return "False"
83
84 #? bool() str()
85 test_function()
86
87 # -----------------
88 # elif
89 # -----------------
90
91 def elif_flows1(x):
92 if False:
93 return 1
94 elif True:
95 return 1.0
96 else:
97 return ''
98
99 #? float()
100 elif_flows1(1)
101
102
103 def elif_flows2(x):
104 try:
105 if False:
106 return 1
107 elif 0:
108 return 1.0
109 else:
110 return ''
111 except ValueError:
112 return set
113
114 #? str() set
115 elif_flows2(1)
116
117
118 def elif_flows3(x):
119 try:
120 if True:
121 return 1
122 elif 0:
123 return 1.0
124 else:
125 return ''
126 except ValueError:
127 return set
128
129 #? int() set
130 elif_flows3(1)
131
132 # -----------------
133 # mid-difficulty if statements
134 # -----------------
135 def check(a):
136 if a is None:
137 return 1
138 return ''
139 return set
140
141 #? int()
142 check(None)
143 #? str()
144 check('asb')
145
146 a = list
147 if 2 == True:
148 a = set
149 elif 1 == True:
150 a = 0
151
152 #? int()
153 a
154 if check != 1:
155 a = ''
156 #? int() str()
157 a
158 if check == check:
159 a = list
160 #? list
161 a
162 if check != check:
163 a = set
164 else:
165 a = dict
166 #? dict
167 a
168 if not (check is not check):
169 a = 1
170 #? int()
171 a
172
173
174 # -----------------
175 # name resolution
176 # -----------------
177
178 a = list
179 def elif_name(x):
180 try:
181 if True:
182 a = 1
183 elif 0:
184 a = 1.0
185 else:
186 return ''
187 except ValueError:
188 a = x
189 return a
190
191 #? int() set
192 elif_name(set)
193
194 if 0:
195 a = ''
196 else:
197 a = int
198
199 #? int
200 a
201
202 # -----------------
203 # isinstance
204 # -----------------
205
206 class A(): pass
207
208 def isinst(x):
209 if isinstance(x, A):
210 return dict
211 elif isinstance(x, int) and x == 1 or x is True:
212 return set
213 elif isinstance(x, (float, reversed)):
214 return list
215 elif not isinstance(x, str):
216 return tuple
217 return 1
218
219 #? dict
220 isinst(A())
221 #? set
222 isinst(True)
223 #? set
224 isinst(1)
225 #? tuple
226 isinst(2)
227 #? list
228 isinst(1.0)
229 #? tuple
230 isinst(False)
231 #? int()
232 isinst('')
233
234 # -----------------
235 # flows that are not reachable should be able to access parent scopes.
236 # -----------------
237
238 foobar = ''
239
240 if 0:
241 within_flow = 1.0
242 #? float()
243 within_flow
244 #? str()
245 foobar
246 if 0:
247 nested = 1
248 #? int()
249 nested
250 #? float()
251 within_flow
252 #? str()
253 foobar
254 #?
255 nested
256
257 if False:
258 in_false = 1
259 #? ['in_false']
260 in_false
261
262 # -----------------
263 # True objects like modules
264 # -----------------
265
266 class X():
267 pass
268 if X:
269 a = 1
270 else:
271 a = ''
272 #? int()
273 a
274
275
276 # -----------------
277 # Recursion issues
278 # -----------------
279
280 def possible_recursion_error(filename):
281 if filename == 'a':
282 return filename
283 # It seems like without the brackets there wouldn't be a RecursionError.
284 elif type(filename) == str:
285 return filename
286
287
288 if NOT_DEFINED:
289 s = str()
290 else:
291 s = str()
292 #? str()
293 possible_recursion_error(s)
294
295
296 # -----------------
297 # In combination with imports
298 # -----------------
299
300 from import_tree import flow_import
301
302 if 1 == flow_import.env:
303 a = 1
304 elif 2 == flow_import.env:
305 a = ''
306 elif 3 == flow_import.env:
307 a = 1.0
308
309 #? int() str()
310 a