Debian Codegraph @

test/completion/functions.py

raw symbols SCIP
1 def x():
2 return
3
4 #? None
5 x()
6
7 def array(first_param):
8 #? ['first_param']
9 first_param
10 return list()
11
12 #? []
13 array.first_param
14 #? []
15 array.first_param.
16 func = array
17 #? []
18 func.first_param
19
20 #? list()
21 array()
22
23 #? ['array']
24 arr
25
26
27 def inputs(param):
28 return param
29
30 #? list
31 inputs(list)
32
33 def variable_middle():
34 var = 3
35 return var
36
37 #? int()
38 variable_middle()
39
40 def variable_rename(param):
41 var = param
42 return var
43
44 #? int()
45 variable_rename(1)
46
47 def multi_line_func(a, # comment blabla
48
49 b):
50 return b
51
52 #? str()
53 multi_line_func(1,'')
54
55 def multi_line_call(b):
56 return b
57
58
59 multi_line_call(
60 #? int()
61 b=1)
62
63
64 # nothing after comma
65 def asdf(a):
66 return a
67
68 x = asdf(a=1,
69 )
70 #? int()
71 x
72
73 # -----------------
74 # double execution
75 # -----------------
76 def double_exe(param):
77 return param
78
79 #? str()
80 variable_rename(double_exe)("")
81
82 # -> shouldn't work (and throw no error)
83 #? []
84 variable_rename(list())().
85 #? []
86 variable_rename(1)().
87
88 # -----------------
89 # recursions (should ignore)
90 # -----------------
91 def recursion(a, b):
92 if a:
93 return b
94 else:
95 return recursion(a+".", b+1)
96
97 # Does not also return int anymore, because we now support operators in simple cases.
98 #? float()
99 recursion("a", 1.0)
100
101 def other(a):
102 return recursion2(a)
103
104 def recursion2(a):
105 if random.choice([0, 1]):
106 return other(a)
107 else:
108 if random.choice([0, 1]):
109 return recursion2("")
110 else:
111 return a
112
113 #? int() str()
114 recursion2(1)
115
116 # -----------------
117 # ordering
118 # -----------------
119
120 def a():
121 #? int()
122 b()
123 return b()
124
125 def b():
126 return 1
127
128 #? int()
129 a()
130
131 # -----------------
132 # keyword arguments
133 # -----------------
134
135 def func(a=1, b=''):
136 return a, b
137
138 exe = func(b=list, a=tuple)
139 #? tuple
140 exe[0]
141
142 #? list
143 exe[1]
144
145 # -----------------
146 # default arguments
147 # -----------------
148
149 #? int()
150 func()[0]
151 #? str()
152 func()[1]
153 #? float()
154 func(1.0)[0]
155 #? str()
156 func(1.0)[1]
157
158
159 #? float()
160 func(a=1.0)[0]
161 #? str()
162 func(a=1.0)[1]
163 #? int()
164 func(b=1.0)[0]
165 #? float()
166 func(b=1.0)[1]
167 #? list
168 func(a=list, b=set)[0]
169 #? set
170 func(a=list, b=set)[1]
171
172
173 def func_default(a, b=1):
174 return a, b
175
176
177 def nested_default(**kwargs):
178 return func_default(**kwargs)
179
180 #? float()
181 nested_default(a=1.0)[0]
182 #? int()
183 nested_default(a=1.0)[1]
184 #? str()
185 nested_default(a=1.0, b='')[1]
186
187 # Defaults should only work if they are defined before - not after.
188 def default_function(a=default):
189 #?
190 return a
191
192 #?
193 default_function()
194
195 default = int()
196
197 def default_function(a=default):
198 #? int()
199 return a
200
201 #? int()
202 default_function()
203
204 def default(a=default):
205 #? int()
206 a
207
208 # -----------------
209 # closures
210 # -----------------
211 def a():
212 l = 3
213 def func_b():
214 l = ''
215 #? str()
216 l
217 #? ['func_b']
218 func_b
219 #? int()
220 l
221
222 # -----------------
223 # *args
224 # -----------------
225
226 def args_func(*args):
227 #? tuple()
228 return args
229
230 exe = args_func(1, "")
231 #? int()
232 exe[0]
233 #? str()
234 exe[1]
235
236 # illegal args (TypeError)
237 #?
238 args_func(*1)[0]
239 # iterator
240 #? int()
241 args_func(*iter([1]))[0]
242
243 # different types
244 e = args_func(*[1 if UNDEFINED else "", {}])
245 #? int() str()
246 e[0]
247 #? dict()
248 e[1]
249
250 _list = [1,""]
251 exe2 = args_func(_list)[0]
252
253 #? str()
254 exe2[1]
255
256 exe3 = args_func([1,""])[0]
257
258 #? str()
259 exe3[1]
260
261 def args_func(arg1, *args):
262 return arg1, args
263
264 exe = args_func(1, "", list)
265 #? int()
266 exe[0]
267 #? tuple()
268 exe[1]
269 #? list
270 exe[1][1]
271
272
273 # In a dynamic search, both inputs should be given.
274 def simple(a):
275 #? int() str()
276 return a
277 def xargs(*args):
278 return simple(*args)
279
280 xargs(1)
281 xargs('')
282
283
284 # *args without a self symbol
285 def memoize(func):
286 def wrapper(*args, **kwargs):
287 return func(*args, **kwargs)
288 return wrapper
289
290
291 class Something():
292 @memoize
293 def x(self, a, b=1):
294 return a
295
296 #? int()
297 Something().x(1)
298
299
300 # -----------------
301 # ** kwargs
302 # -----------------
303 def kwargs_func(**kwargs):
304 #? ['keys']
305 kwargs.keys
306 #? dict()
307 return kwargs
308
309 exe = kwargs_func(a=3,b=4.0)
310 #? dict()
311 exe
312 #? int()
313 exe['a']
314 #? float()
315 exe['b']
316 #? int() float()
317 exe['c']
318
319 a = 'a'
320 exe2 = kwargs_func(**{a:3,
321 'b':4.0})
322
323 #? int()
324 exe2['a']
325 #? float()
326 exe2['b']
327 #? int() float()
328 exe2['c']
329
330 exe3 = kwargs_func(**{k: v for k, v in [(a, 3), ('b', 4.0)]})
331
332 # Should resolve to the same as 2 but jedi is not smart enough yet
333 # Here to make sure it doesn't result in crash though
334 #?
335 exe3['a']
336
337 #?
338 exe3['b']
339
340 #?
341 exe3['c']
342
343 # -----------------
344 # *args / ** kwargs
345 # -----------------
346
347 def func_without_call(*args, **kwargs):
348 #? tuple()
349 args
350 #? dict()
351 kwargs
352
353 def fu(a=1, b="", *args, **kwargs):
354 return a, b, args, kwargs
355
356 exe = fu(list, 1, "", c=set, d="")
357
358 #? list
359 exe[0]
360 #? int()
361 exe[1]
362 #? tuple()
363 exe[2]
364 #? str()
365 exe[2][0]
366 #? dict()
367 exe[3]
368 #? set
369 exe[3]['c']
370
371
372 def kwargs_iteration(**kwargs):
373 return kwargs
374
375 for x in kwargs_iteration(d=3):
376 #? float()
377 {'d': 1.0, 'c': '1'}[x]
378
379
380 # -----------------
381 # nested *args
382 # -----------------
383 def function_args(a, b, c):
384 return b
385
386 def nested_args(*args):
387 return function_args(*args)
388
389 def nested_args2(*args, **kwargs):
390 return nested_args(*args)
391
392 #? int()
393 nested_args('', 1, 1.0, list)
394 #? []
395 nested_args('').
396
397 #? int()
398 nested_args2('', 1, 1.0)
399 #? []
400 nested_args2('').
401
402 # -----------------
403 # nested **kwargs
404 # -----------------
405 def nested_kw(**kwargs1):
406 return function_args(**kwargs1)
407
408 def nested_kw2(**kwargs2):
409 return nested_kw(**kwargs2)
410
411 # invalid command, doesn't need to return anything
412 #?
413 nested_kw(b=1, c=1.0, list)
414 #? int()
415 nested_kw(b=1)
416 # invalid command, doesn't need to return anything
417 #?
418 nested_kw(d=1.0, b=1, list)
419 #? int()
420 nested_kw(a=3.0, b=1)
421 #? int()
422 nested_kw(b=1, a=r"")
423 #? []
424 nested_kw(1, '').
425 #? []
426 nested_kw(a='').
427
428 #? int()
429 nested_kw2(b=1)
430 #? int()
431 nested_kw2(b=1, c=1.0)
432 #? int()
433 nested_kw2(c=1.0, b=1)
434 #? []
435 nested_kw2('').
436 #? []
437 nested_kw2(a='').
438 #? []
439 nested_kw2('', b=1).
440
441 # -----------------
442 # nested *args/**kwargs
443 # -----------------
444 def nested_both(*args, **kwargs):
445 return function_args(*args, **kwargs)
446
447 def nested_both2(*args, **kwargs):
448 return nested_both(*args, **kwargs)
449
450 # invalid commands, may return whatever.
451 #? list
452 nested_both('', b=1, c=1.0, list)
453 #? list
454 nested_both('', c=1.0, b=1, list)
455
456 #? []
457 nested_both('').
458
459 #? int()
460 nested_both2('', b=1, c=1.0)
461 #? int()
462 nested_both2('', c=1.0, b=1)
463 #? []
464 nested_both2('').
465
466 # -----------------
467 # nested *args/**kwargs with a default arg
468 # -----------------
469 def function_def(a, b, c):
470 return a, b
471
472 def nested_def(a, *args, **kwargs):
473 return function_def(a, *args, **kwargs)
474
475 def nested_def2(*args, **kwargs):
476 return nested_def(*args, **kwargs)
477
478 #? str()
479 nested_def2('', 1, 1.0)[0]
480 #? str()
481 nested_def2('', b=1, c=1.0)[0]
482 #? str()
483 nested_def2('', c=1.0, b=1)[0]
484 #? int()
485 nested_def2('', 1, 1.0)[1]
486 #? int()
487 nested_def2('', b=1, c=1.0)[1]
488 #? int()
489 nested_def2('', c=1.0, b=1)[1]
490 #? []
491 nested_def2('')[1].
492
493 # -----------------
494 # magic methods
495 # -----------------
496 def a(): pass
497 #? ['__closure__']
498 a.__closure__