Debian Codegraph @

test/completion/dynamic_arrays.py

raw symbols SCIP
1 """
2 Checking for ``list.append`` and all the other possible array modifications.
3 """
4 # -----------------
5 # list.append
6 # -----------------
7 arr = []
8 for a in [1,2]:
9 arr.append(a);
10
11 arr.append # should not cause an exception
12 arr.append() # should not cause an exception
13
14 #? int()
15 arr[10]
16
17 arr = [tuple()]
18 for a in [1,2]:
19 arr.append(a);
20
21 #? int() tuple()
22 arr[10]
23 #? int()
24 arr[10].index()
25
26 arr = list([])
27 arr.append(1)
28 #? int()
29 arr[0]
30
31 # -----------------
32 # list.insert
33 # -----------------
34 arr = [""]
35 arr.insert(0, 1.0)
36
37 # on exception due to this, please!
38 arr.insert(0)
39 arr.insert()
40
41 #? float() str()
42 arr[10]
43
44 for a in arr:
45 #? float() str()
46 a
47
48 #? float() str()
49 list(arr)[10]
50
51 # -----------------
52 # list.extend / set.update
53 # -----------------
54
55 arr = [1.0]
56 arr.extend([1,2,3])
57 arr.extend([])
58 arr.extend("")
59 arr.extend(list) # should ignore
60
61 #? float() int() str()
62 arr[100]
63
64 a = set(arr)
65 a.update(list(["", 1]))
66
67 #? float() int() str()
68 list(a)[0]
69 # -----------------
70 # set/list initialized as functions
71 # -----------------
72
73 st = set()
74 st.add(1)
75
76 #? int()
77 for s in st: s
78
79 lst = list()
80 lst.append(1)
81
82 #? int()
83 for i in lst: i
84
85 # -----------------
86 # renames / type changes
87 # -----------------
88 arr = []
89 arr2 = arr
90 arr2.append('')
91 #? str()
92 arr2[0]
93
94
95 lst = [1]
96 lst.append(1.0)
97 s = set(lst)
98 s.add("ahh")
99 lst = list(s)
100 lst.append({})
101
102 #? dict() int() float() str()
103 lst[0]
104
105 # should work with tuple conversion, too.
106 #? dict() int() float() str()
107 tuple(lst)[0]
108
109 # but not with an iterator
110 #?
111 iter(lst)[0]
112
113 # -----------------
114 # complex including +=
115 # -----------------
116 class C(): pass
117 class D(): pass
118 class E(): pass
119 lst = [1]
120 lst.append(1.0)
121 lst += [C()]
122 s = set(lst)
123 s.add("")
124 s += [D()]
125 lst = list(s)
126 lst.append({})
127 lst += [E()]
128
129 #? dict() int() float() str() C() D() E()
130 lst[0]
131
132 # -----------------
133 # functions
134 # -----------------
135
136 def arr_append(arr4, a):
137 arr4.append(a)
138
139 def add_to_arr(arr2, a):
140 arr2.append(a)
141 return arr2
142
143 def app(a):
144 arr3.append(a)
145
146 arr3 = [1.0]
147 res = add_to_arr(arr3, 1)
148 arr_append(arr3, 'str')
149 app(set())
150
151 #? float() str() int() set()
152 arr3[10]
153
154 #? float() str() int() set()
155 res[10]
156
157 # -----------------
158 # returns, special because the module dicts are not correct here.
159 # -----------------
160 def blub():
161 a = []
162 a.append(1.0)
163 #? float()
164 a[0]
165 return a
166
167 #? float()
168 blub()[0]
169
170 # list with default
171 def blub():
172 a = list([1])
173 a.append(1.0)
174 return a
175
176 #? int() float()
177 blub()[0]
178
179 # empty list
180 def blub():
181 a = list()
182 a.append(1.0)
183 return a
184 #? float()
185 blub()[0]
186
187 # with if
188 def blub():
189 if 1:
190 a = []
191 a.append(1.0)
192 return a
193
194 #? float()
195 blub()[0]
196
197 # with else clause
198 def blub():
199 if random.choice([0, 1]):
200 1
201 else:
202 a = []
203 a.append(1)
204 return a
205
206 #? int()
207 blub()[0]
208 # -----------------
209 # returns, the same for classes
210 # -----------------
211 class C():
212 def blub(self, b):
213 if 1:
214 a = []
215 a.append(b)
216 return a
217
218 def blub2(self):
219 """ mapper function """
220 a = self.blub(1.0)
221 #? float()
222 a[0]
223 return a
224
225 def literal_arr(self, el):
226 self.a = []
227 self.a.append(el)
228 #? int()
229 self.a[0]
230 return self.a
231
232 def list_arr(self, el):
233 self.b = list([])
234 self.b.append(el)
235 #? float()
236 self.b[0]
237 return self.b
238
239 #? int()
240 C().blub(1)[0]
241 #? float()
242 C().blub2(1)[0]
243
244 #? int()
245 C().a[0]
246 #? int()
247 C().literal_arr(1)[0]
248
249 #? float()
250 C().b[0]
251 #? float()
252 C().list_arr(1.0)[0]
253
254 # -----------------
255 # array recursions
256 # -----------------
257
258 a = set([1.0])
259 a.update(a)
260 a.update([1])
261
262 #? float() int()
263 list(a)[0]
264
265 def first(a):
266 b = []
267 b.append(a)
268 b.extend(second(a))
269 return list(b)
270
271 def second(a):
272 b = []
273 b.extend(first(a))
274 return list(b)
275
276 #? float()
277 first(1.0)[0]
278
279 def third():
280 b = []
281 b.extend
282 extend()
283 b.extend(first())
284 return list(b)
285 #?
286 third()[0]
287
288
289 # -----------------
290 # set.add
291 # -----------------
292 st = {1.0}
293 for a in [1,2]:
294 st.add(a)
295
296 st.append('') # lists should not have an influence
297
298 st.add # should not cause an exception
299 st.add()
300
301 st = {1.0}
302 st.add(1)
303 lst = list(st)
304
305 lst.append('')
306
307 #? float() int() str()
308 lst[0]
309
310 # -----------------
311 # list setitem
312 # -----------------
313
314 some_lst = [int]
315 some_lst[3] = str
316 #? int
317 some_lst[0]
318 #? str
319 some_lst[3]
320 #? int str
321 some_lst[2]
322
323 some_lst[0] = tuple
324 #? tuple
325 some_lst[0]
326 #? int str tuple
327 some_lst[1]
328
329 some_lst2 = list([1])
330 some_lst2[3] = ''
331 #? int() str()
332 some_lst2[0]
333 #? str()
334 some_lst2[3]
335 #? int() str()
336 some_lst2[2]
337
338 some_lst3 = []
339 some_lst3[0] = 3
340 some_lst3[:] = '' # Is ignored for now.
341 #? int()
342 some_lst3[0]
343 # -----------------
344 # set setitem/other modifications (should not work)
345 # -----------------
346
347 some_set = {int}
348 some_set[3] = str
349 #? int
350 some_set[0]
351 #? int
352 some_set[3]
353
354 something = object()
355 something[3] = str
356 #?
357 something[0]
358 #?
359 something[3]
360
361 # -----------------
362 # dict setitem
363 # -----------------
364
365 some_dct = {'a': float, 1: int}
366 some_dct['x'] = list
367 some_dct['y'] = tuple
368 #? list
369 some_dct['x']
370 #? int float list tuple
371 some_dct['unknown']
372 #? float
373 some_dct['a']
374
375 some_dct = dict({'a': 1, 1: ''})
376 #? int() str()
377 some_dct['la']
378 #? int()
379 some_dct['a']
380
381 some_dct['x'] = list
382 some_dct['y'] = tuple
383 #? list
384 some_dct['x']
385 #? int() str() list tuple
386 some_dct['unknown']
387 k = 'a'
388 #? int()
389 some_dct[k]
390
391 some_other_dct = dict(some_dct, c=set)
392 #? int()
393 some_other_dct['a']
394 #? list
395 some_other_dct['x']
396 #? set
397 some_other_dct['c']