Debian Codegraph @

test/completion/arrays.py

raw symbols SCIP
1 # -----------------
2 # basic array lookups
3 # -----------------
4
5
6 #? int()
7 [1,""][0]
8 #? str()
9 [1,""][1]
10 #? int() str()
11 [1,""][2]
12 #? int() str()
13 [1,""][20]
14 #? int() str()
15 [1,""][str(hello)]
16
17 a = list()
18 #? list()
19 [a][0]
20
21 #? list()
22 [[a,a,a]][2][100]
23
24 c = [[a,""]]
25 #? str()
26 c[0][1]
27
28 b = [6,7]
29
30 #? int()
31 b[8-7]
32 # Something unreasonable:
33 #? int()
34 b['']
35
36 # -----------------
37 # Slices
38 # -----------------
39 #? list()
40 b[8:]
41
42 #? list()
43 b[int():]
44
45 #? list()
46 b[:]
47 #? int()
48 b[:, :-1]
49
50 #? 3
51 b[:]
52
53 #? int()
54 b[:, 1]
55 #? int()
56 b[:1, 1]
57 #? int()
58 b[1:1, 1]
59 #? int()
60 b[1:1:, ...]
61 #? int()
62 b[1:1:5, ...]
63
64 class _StrangeSlice():
65 def __getitem__(self, sliced):
66 return sliced
67
68 # Should not result in an error, just because the slice itself is returned.
69 #? slice()
70 _StrangeSlice()[1:2]
71
72 for x in b[:]:
73 #? int()
74 x
75
76 for x in b[:, :-1]:
77 #?
78 x
79
80 class Foo:
81 def __getitem__(self, item):
82 return item
83
84 #?
85 Foo()[:, :-1][0]
86
87 # -----------------
88 # iterable multiplication
89 # -----------------
90 a = ['']*2
91 #? list()
92 a
93
94 # -----------------
95 # tuple assignments
96 # -----------------
97 a1, b1 = (1, "")
98 #? int()
99 a1
100 #? str()
101 b1
102
103 (a2, b2) = (1, "")
104 #? int()
105 a2
106 #? str()
107 b2
108
109 # list assignment
110 [list1, list2] = (1, "")
111 #? int()
112 list1
113 #? str()
114 list2
115
116 [list3, list4] = [1, ""]
117 #? int()
118 list3
119 #? str()
120 list4
121
122 # -----------------
123 # subtuple assignment
124 # -----------------
125 (a3, (b3, c3)) = (1, ("", list))
126 #? list
127 c3
128
129 a4, (b4, c4) = (1, ("", list))
130 #? list
131 c4
132 #? int()
133 a4
134 #? str()
135 b4
136
137
138 # -----------------
139 # multiple assignments
140 # -----------------
141 a = b = 1
142 #? int()
143 a
144 #? int()
145 b
146
147 (a, b) = (c, (e, f)) = ('2', (3, 4))
148 #? str()
149 a
150 #? tuple()
151 b
152 #? str()
153 c
154 #? int()
155 e
156 #? int()
157 f
158
159
160 # -----------------
161 # unnessecary braces
162 # -----------------
163 a = (1)
164 #? int()
165 a
166 #? int()
167 (1)
168 #? int()
169 ((1))
170 #? int()
171 ((1)+1)
172
173 u, v = 1, ""
174 #? int()
175 u
176
177 ((u1, v1)) = 1, ""
178 #? int()
179 u1
180 #? int()
181 (u1)
182
183 (a), b = 1, ''
184 #? int()
185 a
186
187 def a(): return ''
188 #? str()
189 (a)()
190 #? str()
191 (a)().title()
192 #? int()
193 (tuple).index()
194 #? int()
195 (tuple)().index()
196
197 class C():
198 def __init__(self):
199 self.a = (str()).upper()
200
201 #? str()
202 C().a
203
204 # -----------------
205 # imbalanced sides
206 # -----------------
207 (f, g) = (1,)
208 #? int()
209 f
210 #? int()
211 g
212
213 (f, g, h) = (1,'')
214 #? int()
215 f
216 #? str()
217 g
218 #? str()
219 h
220
221 (f1, g1) = 1
222 #? []
223 f1.
224 #? []
225 g1.
226
227 (f, g) = (1,'',1.0)
228 #? int()
229 f
230 #? str()
231 g
232
233 # -----------------
234 # setitem
235 # -----------------
236
237 class F:
238 setitem_x = [1,2]
239 setitem_x[0] = 3
240
241 #? ['setitem_x']
242 F().setitem_x
243 #? list()
244 F().setitem_x
245
246
247 # -----------------
248 # dicts
249 # -----------------
250 dic2 = {'asdf': 3, 'b': 'str'}
251 #? int()
252 dic2['asdf']
253 #? None int() str()
254 dic2.get('asdf')
255
256 # string literal
257 #? int()
258 dic2[r'asdf']
259 #? int()
260 dic2[r'asdf']
261 #? int()
262 dic2[r'as' 'd' u'f']
263 #? int() str()
264 dic2['just_something']
265
266 # unpacking
267 a, b = dic2
268 #? str()
269 a
270 a, b = {1: 'x', 2.0: 1j}
271 #? int() float()
272 a
273 #? int() float()
274 b
275
276
277 def f():
278 """ github #83 """
279 r = {}
280 r['status'] = (200, 'ok')
281 return r
282
283 #? dict()
284 f()
285
286 # completion within dicts
287 #? 9 ['str']
288 {str: str}
289
290 # iteration problem (detected with sith)
291 d = dict({'a':''})
292 def y(a):
293 return a
294 #?
295 y(**d)
296
297 #? str()
298 d['a']
299
300 # problem with more complicated casts
301 dic = {str(key): ''}
302 #? str()
303 dic['']
304
305
306 for x in {1: 3.0, '': 1j}:
307 #? int() str()
308 x
309
310 #? ['__iter__']
311 dict().values().__iter__
312
313 d = dict(a=3, b='')
314 x, y, z = d.values()
315 #? int() str()
316 x
317 #? int() str()
318 y
319 #? int() str()
320 z
321 #? int()
322 d['a']
323 #? int() str() None
324 d.get('a')
325
326 some_dct = dict({'a': 1, 'b': ''}, a=1.0)
327 #? float()
328 some_dct['a']
329 #? str()
330 some_dct['b']
331 #? int() float() str()
332 some_dct['c']
333
334 class Foo:
335 pass
336
337 objects = {object(): 1, Foo: '', Foo(): 3.0}
338 #? int() float() str()
339 objects[Foo]
340 #? int() float() str()
341 objects[Foo()]
342 #? int() float() str()
343 objects['']
344
345 # -----------------
346 # with variable as index
347 # -----------------
348 a = (1, "")
349 index = 1
350 #? str()
351 a[index]
352
353 # these should just ouput the whole array
354 index = int
355 #? int() str()
356 a[index]
357 index = int()
358 #? int() str()
359 a[index]
360
361 # dicts
362 index = 'asdf'
363
364 dic2 = {'asdf': 3, 'b': 'str'}
365 #? int()
366 dic2[index]
367
368 # -----------------
369 # __getitem__
370 # -----------------
371
372 class GetItem():
373 def __getitem__(self, index):
374 return 1.0
375
376 #? float()
377 GetItem()[0]
378
379 class GetItem():
380 def __init__(self, el):
381 self.el = el
382
383 def __getitem__(self, index):
384 return self.el
385
386 #? str()
387 GetItem("")[1]
388
389 class GetItemWithList():
390 def __getitem__(self, index):
391 return [1, 1.0, 's'][index]
392
393 #? float()
394 GetItemWithList()[1]
395
396 for i in 0, 2:
397 #? int() str()
398 GetItemWithList()[i]
399
400
401 # With super
402 class SuperYeah(list):
403 def __getitem__(self, index):
404 return super()[index]
405
406 #?
407 SuperYeah([1])[0]
408 #?
409 SuperYeah()[0]
410
411 # -----------------
412 # conversions
413 # -----------------
414
415 a = [1, ""]
416 #? int() str()
417 list(a)[1]
418
419 #? int() str()
420 list(a)[0]
421 #?
422 set(a)[0]
423
424 #? int() str()
425 list(set(a))[1]
426 #? int() str()
427 next(iter(set(a)))
428 #? int() str()
429 list(list(set(a)))[1]
430
431 # does not yet work, because the recursion catching is not good enough (catches # to much)
432 #? int() str()
433 list(set(list(set(a))))[1]
434 #? int() str()
435 list(set(set(a)))[1]
436
437 # frozenset
438 #? int() str()
439 list(frozenset(a))[1]
440 #? int() str()
441 list(set(frozenset(a)))[1]
442
443 # iter
444 #? int() str()
445 list(iter(a))[1]
446 #? int() str()
447 list(iter(list(set(a))))[1]
448
449 # tuple
450 #? int() str()
451 tuple(a)[1]
452 #? int() str()
453 tuple(list(set(a)))[1]
454
455 #? int()
456 tuple((1,))[0]
457
458 # implementation detail for lists, should not be visible
459 #? []
460 list().__iterable
461
462 # With a list comprehension.
463 for i in set(a for a in [1]):
464 #? int()
465 i
466
467
468 # -----------------
469 # Merged Arrays
470 # -----------------
471
472 for x in [1] + ['']:
473 #? int() str()
474 x
475
476 # -----------------
477 # Potential Recursion Issues
478 # -----------------
479 class X():
480 def y(self):
481 self.a = [1]
482
483 def x(self):
484 self.a = list(self.a)
485 #? int()
486 self.a[0]
487
488 # -----------------
489 # For loops with attribute assignment.
490 # -----------------
491 def test_func():
492 x = 'asdf'
493 for x.something in [6,7,8]:
494 pass
495 #? str()
496 x
497
498 for x.something, b in [[6, 6.0]]:
499 pass
500 #? str()
501 x
502
503
504 #? int()
505 tuple({1})[0]
506
507 # -----------------
508 # PEP 3132 Extended Iterable Unpacking (star unpacking)
509 # -----------------
510
511 a, *b, c = [1, 'b', list, dict]
512 #? int()
513 a
514 #?
515 b
516 #? list
517 c
518
519 # Not valid syntax
520 a, *b, *c = [1, 'd', list]
521 #? int()
522 a
523 #?
524 b
525 #?
526 c
527
528 lc = [x for a, *x in [(1, '', 1.0)]]
529
530 #?
531 lc[0][0]
532 #?
533 lc[0][1]
534
535
536 xy = (1,)
537 x, y = *xy, None
538
539 # whatever it is should not crash
540 #?
541 x