Debian Codegraph @

test/completion/basic.py

raw symbols SCIP
1 # -----------------
2 # cursor position
3 # -----------------
4 #? 0 int
5 int()
6 #? 3 int
7 int()
8 #? 4 str
9 int(str)
10
11
12 # -----------------
13 # should not complete
14 # -----------------
15 #? []
16 .
17 #? []
18 str..
19 #? []
20 a(0):.
21 #? 2 []
22 0x0
23 #? []
24 1j
25 #? ['and', 'or', 'if', 'is', 'in', 'not']
26 1j
27 x = None()
28 #?
29 x
30
31 # -----------------
32 # if/else/elif
33 # -----------------
34
35 if (random.choice([0, 1])):
36 1
37 elif(random.choice([0, 1])):
38 a = 3
39 else:
40 a = ''
41 #? int() str()
42 a
43 def func():
44 if random.choice([0, 1]):
45 1
46 elif(random.choice([0, 1])):
47 a = 3
48 else:
49 a = ''
50 #? int() str()
51 return a
52 #? int() str()
53 func()
54
55 # -----------------
56 # keywords
57 # -----------------
58
59 #? list()
60 assert []
61
62 def focus_return():
63 #? list()
64 return []
65
66
67 # -----------------
68 # for loops
69 # -----------------
70
71 for a in [1,2]:
72 #? int()
73 a
74
75 for a1 in 1,"":
76 #? int() str()
77 a1
78
79 for a3, b3 in (1,""), (1,""), (1,""):
80 #? int()
81 a3
82 #? str()
83 b3
84 for (a3, b3) in (1,""), (1,""), (1,""):
85 #? int()
86 a3
87 #? str()
88 b3
89
90 for a4, (b4, c4) in (1,("", list)), (1,("", list)):
91 #? int()
92 a4
93 #? str()
94 b4
95 #? list
96 c4
97
98 a = []
99 for i in [1,'']:
100 #? int() str()
101 i
102 a += [i]
103
104 #? int() str()
105 a[0]
106
107 for i in list([1,'']):
108 #? int() str()
109 i
110
111 #? int() str()
112 for x in [1,'']: x
113
114 a = []
115 b = [1.0,'']
116 for i in b:
117 a += [i]
118
119 #? float() str()
120 a[0]
121
122 for i in [1,2,3]:
123 #? int()
124 i
125 else:
126 i
127
128
129 # -----------------
130 # range()
131 # -----------------
132 for i in range(10):
133 #? int()
134 i
135
136 # -----------------
137 # ternary operator
138 # -----------------
139
140 a = 3
141 b = '' if a else set()
142 #? str() set()
143 b
144
145 def ret(a):
146 return ['' if a else set()]
147
148 #? str() set()
149 ret(1)[0]
150 #? str() set()
151 ret()[0]
152
153 # -----------------
154 # global vars
155 # -----------------
156
157 def global_define():
158 #? int()
159 global global_var_in_func
160 global_var_in_func = 3
161
162 #? int()
163 global_var_in_func
164
165 #? ['global_var_in_func']
166 global_var_in_f
167
168
169 def funct1():
170 # From issue #610
171 global global_dict_var
172 global_dict_var = dict()
173 def funct2():
174 #! ['global_dict_var', 'global_dict_var']
175 global global_dict_var
176 #? dict()
177 global_dict_var
178
179
180 global_var_predefined = None
181
182 def init_global_var_predefined():
183 global global_var_predefined
184 if global_var_predefined is None:
185 global_var_predefined = 3
186
187 #? int() None
188 global_var_predefined
189
190
191 def global_as_import():
192 from import_tree import globals
193 #? ['foo']
194 globals.foo
195 #? int()
196 globals.foo
197
198
199 global r
200 r = r[r]
201 if r:
202 r += r + 2
203 #? int()
204 r
205
206 # -----------------
207 # del
208 # -----------------
209
210 deleted_var = 3
211 del deleted_var
212 #?
213 deleted_var
214 #? []
215 deleted_var
216 #! []
217 deleted_var
218
219 # -----------------
220 # within docstrs
221 # -----------------
222
223 def a():
224 """
225 #? []
226 global_define
227 #?
228 str
229 """
230 pass
231
232 #?
233 # str literals in comment """ upper
234
235 # python >= 3.11
236 def completion_in_comment():
237 #? ['Exception', 'ExceptionGroup']
238 # might fail because the comment is not a leaf: Exception
239 pass
240
241 some_word
242 #? ['Exception', 'ExceptionGroup']
243 # Very simple comment completion: Exception
244 # Commment after it
245
246 # -----------------
247 # magic methods
248 # -----------------
249
250 class A(object): pass
251 class B(): pass
252
253 #? ['__init__']
254 A.__init__
255 #? ['__init__']
256 B.__init__
257
258 #? ['__init__']
259 int().__init__
260
261 # -----------------
262 # comments
263 # -----------------
264
265 class A():
266 def __init__(self):
267 self.hello = {} # comment shouldn't be a string
268 #? dict()
269 A().hello
270
271 # -----------------
272 # unicode
273 # -----------------
274 a = 'smörbröd'
275 #? str()
276 a
277 xyz = 'smörbröd.py'
278 if 1:
279 #? str()
280 xyz
281
282 #?
283 ¹.
284
285 # -----------------
286 # exceptions
287 # -----------------
288 try:
289 import math
290 except ImportError as i_a:
291 #? ['i_a']
292 i_a
293 #? ImportError()
294 i_a
295
296
297 class MyException(Exception):
298 def __init__(self, my_attr):
299 self.my_attr = my_attr
300
301 try:
302 raise MyException(1)
303 except MyException as e:
304 #? ['my_attr']
305 e.my_attr
306 #? 22 ['my_attr']
307 for x in e.my_attr:
308 pass
309
310 # -----------------
311 # params
312 # -----------------
313
314 my_param = 1
315 #? 9 str()
316 def foo1(my_param):
317 my_param = 3.0
318 foo1("")
319
320 my_type = float()
321 #? 20 float()
322 def foo2(my_param: my_type):
323 pass
324 foo2("")
325 #? 20 int()
326 def foo3(my_param=my_param):
327 pass
328 foo3("")
329
330 some_default = ''
331 #? []
332 def foo(my_t
333 #? []
334 def foo(my_t, my_ty
335 #? ['some_default']
336 def foo(my_t=some_defa
337 #? ['some_default']
338 def foo(my_t=some_defa, my_t2=some_defa
339
340 #? ['my_type']
341 def foo(my_t: lala=some_defa, my_t2: my_typ
342 #? ['my_type']
343 def foo(my_t: lala=some_defa, my_t2: my_typ
344 #? []
345 def foo(my_t: lala=some_defa, my_t
346
347 #? []
348 lambda my_t
349 #? []
350 lambda my_, my_t
351 #? ['some_default']
352 lambda x=some_defa
353 #? ['some_default']
354 lambda y, x=some_defa
355
356 # Just make sure we're not in some weird parsing recovery after opening brackets
357 def
358
359 # -----------------
360 # continuations
361 # -----------------
362
363 foo = \
364 1
365 #? int()
366 foo
367
368 # -----------------
369 # module attributes
370 # -----------------
371
372 # Don't move this to imports.py, because there's a star import.
373 #? str()
374 __file__
375 #? ['__file__']
376 __file__
377
378 #? str()
379 math.__file__
380 # Should not lead to errors
381 #?
382 math()
383
384 # -----------------
385 # with statements
386 # -----------------
387
388 with open('') as f:
389 #? ['closed']
390 f.closed
391 for line in f:
392 # TODO this is wrong
393 #? bytes()
394 line
395
396 with open('') as f1, open('') as f2:
397 #? ['closed']
398 f1.closed
399 #? ['closed']
400 f2.closed
401
402
403 class Foo():
404 def __enter__(self):
405 return ''
406
407 #? 14 str()
408 with Foo() as f3:
409 #? str()
410 f3
411 #! 14 ['with Foo() as f3: f3']
412 with Foo() as f3:
413 f3
414 #? 6 Foo
415 with Foo() as f3:
416 f3
417
418 with open("a"), open("b") as bfile:
419 #? ['flush']
420 bfile.flush
421
422 # -----------------
423 # Avoiding multiple definitions
424 # -----------------
425
426 some_array = ['', '']
427 #! ['def upper']
428 some_array[some_not_defined_index].upper
429
430 # -----------------
431 # operator
432 # -----------------
433
434 #? bool()
435 res = 'f' in 'foo'; res
436
437 #? bool()
438 res = not {}; res