Debian Codegraph @

test/completion/classes.py

raw symbols SCIP
1 def find_class():
2 """ This scope is special, because its in front of TestClass """
3 #? ['ret']
4 TestClass.ret
5 if 1:
6 #? ['ret']
7 TestClass.ret
8
9 class FindClass():
10 #? []
11 TestClass.ret
12 if a:
13 #? []
14 TestClass.ret
15
16 def find_class(self):
17 #? ['ret']
18 TestClass.ret
19 if 1:
20 #? ['ret']
21 TestClass.ret
22
23 #? []
24 FindClass().find_class.self
25 #? []
26 FindClass().find_class.self.find_class
27
28 # set variables, which should not be included, because they don't belong to the
29 # class
30 second = 1
31 second = ""
32 class TestClass(object):
33 var_class = TestClass(1)
34 self.pseudo_var = 3
35
36 def __init__(self2, first_param, second_param, third=1.0):
37 self2.var_inst = first_param
38 self2.second = second_param
39 self2.first = first_param
40 self2.first.var_on_argument = 5
41 a = 3
42
43 def var_func(self):
44 return 1
45
46 def get_first(self):
47 # traversal
48 self.second_new = self.second
49 return self.var_inst
50
51 def values(self):
52 self.var_local = 3
53 #? ['var_class', 'var_func', 'var_inst', 'var_local']
54 self.var_
55 #?
56 var_local
57
58 def ret(self, a1):
59 # should not know any class functions!
60 #? []
61 values
62 #?
63 values
64 #? ['return']
65 ret
66 return a1
67
68 # should not work
69 #? []
70 var_local
71 #? []
72 var_inst
73 #? []
74 var_func
75
76 # instance
77 inst = TestClass(1)
78
79 #? ['var_class', 'var_func', 'var_inst', 'var_local']
80 inst.var
81
82 #? ['var_class', 'var_func']
83 TestClass.var
84
85 #? int()
86 inst.var_local
87 #? []
88 TestClass.var_local.
89 #?
90 TestClass.pseudo_var
91 #?
92 TestClass().pseudo_var
93
94 #? int()
95 TestClass().ret(1)
96 # Should not return int(), because we want the type before `.ret(1)`.
97 #? 11 TestClass()
98 TestClass().ret(1)
99 #? int()
100 inst.ret(1)
101
102 myclass = TestClass(1, '', 3.0)
103 #? int()
104 myclass.get_first()
105 #? []
106 myclass.get_first.real
107
108 # too many params
109 #? int()
110 TestClass(1,1,1).var_inst
111
112 # too few params
113 #? int()
114 TestClass(1).first
115 #? []
116 TestClass(1).second.
117
118 # complicated variable settings in class
119 #? str()
120 myclass.second
121 #? str()
122 myclass.second_new
123
124 # multiple classes / ordering
125 ints = TestClass(1, 1.0)
126 strs = TestClass("", '')
127 #? float()
128 ints.second
129 #? str()
130 strs.second
131
132 #? ['var_class']
133 TestClass.var_class.var_class.var_class.var_class
134
135 # operations (+, *, etc) shouldn't be InstanceElements - #246
136 class A():
137 def __init__(self):
138 self.addition = 1 + 2
139 #? int()
140 A().addition
141
142 # should also work before `=`
143 #? 8 int()
144 A().addition = None
145 #? 8 int()
146 A(1).addition = None
147 #? 1 A
148 A(1).addition = None
149 a = A()
150 #? 8 int()
151 a.addition = None
152
153
154 # -----------------
155 # inheritance
156 # -----------------
157
158 class Base(object):
159 def method_base(self):
160 return 1
161
162 class SuperClass(Base):
163 class_super = 3
164 def __init__(self):
165 self.var_super = ''
166 def method_super(self):
167 self.var2_super = list
168
169 class Mixin(SuperClass):
170 def method_mixin(self):
171 return int
172
173 #? 20 SuperClass
174 class SubClass(SuperClass):
175 class_sub = 3
176 def __init__(self):
177 self.var_sub = ''
178 def method_sub(self):
179 self.var_sub = list
180 return tuple
181
182 instance = SubClass()
183
184 #? ['method_base', 'method_sub', 'method_super']
185 instance.method_
186 #? ['var2_super', 'var_sub', 'var_super']
187 instance.var
188 #? ['class_sub', 'class_super']
189 instance.class_
190
191 #? ['method_base', 'method_sub', 'method_super']
192 SubClass.method_
193 #? []
194 SubClass.var
195 #? ['class_sub', 'class_super']
196 SubClass.class_
197
198 # -----------------
199 # inheritance of builtins
200 # -----------------
201
202 class Base(str):
203 pass
204
205 #? ['upper']
206 Base.upper
207 #? ['upper']
208 Base().upper
209
210 # -----------------
211 # dynamic inheritance
212 # -----------------
213
214 class Angry(object):
215 def shout(self):
216 return 'THIS IS MALARKEY!'
217
218 def classgetter():
219 return Angry
220
221 class Dude(classgetter()):
222 def react(self):
223 #? ['shout']
224 self.s
225
226 # -----------------
227 # multiple inheritance # 1071
228 # -----------------
229
230 class FactorMixin(object):
231 FACTOR_1 = 0.1
232
233 class Calc(object):
234 def sum(self, a, b):
235 self.xxx = 3
236 return a + b
237
238 class BetterCalc(Calc, FactorMixin):
239 def multiply_factor(self, a):
240 return a * self.FACTOR_1
241
242 calc = BetterCalc()
243 #? ['sum']
244 calc.sum
245 #? ['multiply_factor']
246 calc.multip
247 #? ['FACTOR_1']
248 calc.FACTOR_1
249 #? ['xxx']
250 calc.xxx
251
252 # -----------------
253 # __call__
254 # -----------------
255
256 class CallClass():
257 def __call__(self):
258 return 1
259
260 #? int()
261 CallClass()()
262
263 # -----------------
264 # variable assignments
265 # -----------------
266
267 class V:
268 def __init__(self, a):
269 self.a = a
270
271 def ret(self):
272 return self.a
273
274 d = b
275 b = ret
276 if 1:
277 c = b
278
279 #? int()
280 V(1).b()
281 #? int()
282 V(1).c()
283 #?
284 V(1).d()
285 # Only keywords should be possible to complete.
286 #? ['is', 'in', 'not', 'and', 'or', 'if']
287 V(1).d()
288
289
290 # -----------------
291 # ordering
292 # -----------------
293 class A():
294 def b(self):
295 #? int()
296 a_func()
297 #? str()
298 self.a_func()
299 return a_func()
300
301 def a_func(self):
302 return ""
303
304 def a_func():
305 return 1
306
307 #? int()
308 A().b()
309 #? str()
310 A().a_func()
311
312 # -----------------
313 # nested classes
314 # -----------------
315 class A():
316 class B():
317 pass
318 def b(self):
319 return 1.0
320
321 #? float()
322 A().b()
323
324 class A():
325 def b(self):
326 class B():
327 def b(self):
328 return []
329 return B().b()
330
331 #? list()
332 A().b()
333
334 # -----------------
335 # ducktyping
336 # -----------------
337
338 def meth(self):
339 return self.a, self.b
340
341 class WithoutMethod():
342 a = 1
343 def __init__(self):
344 self.b = 1.0
345 def blub(self):
346 return self.b
347 m = meth
348
349 class B():
350 b = ''
351
352 a = WithoutMethod().m()
353 #? int()
354 a[0]
355 #? float()
356 a[1]
357
358 #? float()
359 WithoutMethod.blub(WithoutMethod())
360 #? str()
361 WithoutMethod.blub(B())
362
363 # -----------------
364 # __getattr__ / getattr() / __getattribute__
365 # -----------------
366
367 #? str().upper
368 getattr(str(), 'upper')
369 #? str.upper
370 getattr(str, 'upper')
371
372 # some strange getattr calls
373 #?
374 getattr(str, 1)
375 #?
376 getattr()
377 #?
378 getattr(str)
379 #?
380 getattr(getattr, 1)
381 #?
382 getattr(str, [])
383
384
385 class Base():
386 def ret(self, b):
387 return b
388
389 class Wrapper():
390 def __init__(self, obj):
391 self.obj = obj
392
393 def __getattr__(self, name):
394 return getattr(self.obj, name)
395
396 class Wrapper2():
397 def __getattribute__(self, name):
398 return getattr(Base(), name)
399
400 #? int()
401 Wrapper(Base()).ret(3)
402 #? ['ret']
403 Wrapper(Base()).ret
404 #? int()
405 Wrapper(Wrapper(Base())).ret(3)
406 #? ['ret']
407 Wrapper(Wrapper(Base())).ret
408
409 #? int()
410 Wrapper2(Base()).ret(3)
411
412 class GetattrArray():
413 def __getattr__(self, name):
414 return [1]
415
416 #? int()
417 GetattrArray().something[0]
418 #? []
419 GetattrArray().something
420
421 class WeirdGetattr:
422 class __getattr__():
423 pass
424
425 #? []
426 WeirdGetattr().something
427
428
429 # -----------------
430 # private vars
431 # -----------------
432 class PrivateVar():
433 def __init__(self):
434 self.__var = 1
435 #? int()
436 self.__var
437 #? ['__var']
438 self.__var
439
440 def __private_func(self):
441 return 1
442
443 #? int()
444 __private_func()
445
446 def wrap_private(self):
447 return self.__private_func()
448 #? []
449 PrivateVar().__var
450 #?
451 PrivateVar().__var
452 #? []
453 PrivateVar().__private_func
454 #? []
455 PrivateVar.__private_func
456 #? int()
457 PrivateVar().wrap_private()
458
459
460 class PrivateSub(PrivateVar):
461 def test(self):
462 #? []
463 self.__var
464
465 def wrap_private(self):
466 #? []
467 self.__var
468
469 #? []
470 PrivateSub().__var
471
472 # -----------------
473 # super
474 # -----------------
475 class Super(object):
476 a = 3
477 def return_sup(self):
478 return 1
479 SuperCopy = Super
480
481 class TestSuper(Super):
482 #?
483 super()
484 def test(self):
485 #? SuperCopy()
486 super()
487 #? ['a']
488 super().a
489 if 1:
490 #? SuperCopy()
491 super()
492 def a():
493 #?
494 super()
495
496 def return_sup(self):
497 #? int()
498 return super().return_sup()
499
500 #? int()
501 TestSuper().return_sup()
502
503
504 Super = 3
505
506 class Foo():
507 def foo(self):
508 return 1
509 # Somehow overwriting the same name caused problems (#1044)
510 class Foo(Foo):
511 def foo(self):
512 #? int()
513 super().foo()
514
515 # -----------------
516 # if flow at class level
517 # -----------------
518 class TestX(object):
519 def normal_method(self):
520 return 1
521
522 if True:
523 def conditional_method(self):
524 var = self.normal_method()
525 #? int()
526 var
527 return 2
528
529 def other_method(self):
530 var = self.conditional_method()
531 #? int()
532 var
533
534 # -----------------
535 # mro method
536 # -----------------
537
538 class A(object):
539 a = 3
540
541 #? ['mro']
542 A.mro
543 #? []
544 A().mro
545
546
547 # -----------------
548 # mro resolution
549 # -----------------
550
551 class B(A()):
552 b = 3
553
554 #?
555 B.a
556 #?
557 B().a
558 #? int()
559 B.b
560 #? int()
561 B().b
562
563
564 # -----------------
565 # With import
566 # -----------------
567
568 from import_tree.classes import Config2, BaseClass
569
570 class Config(BaseClass):
571 """#884"""
572
573 #? Config2()
574 Config.mode
575
576 #? int()
577 Config.mode2
578
579
580 # -----------------
581 # Nested class/def/class
582 # -----------------
583 class Foo(object):
584 a = 3
585 def create_class(self):
586 class X():
587 a = self.a
588 self.b = 3.0
589 return X
590
591 #? int()
592 Foo().create_class().a
593 #? float()
594 Foo().b
595
596 class Foo(object):
597 def comprehension_definition(self):
598 return [1 for self.b in [1]]
599
600 #? int()
601 Foo().b
602
603 # -----------------
604 # default arguments
605 # -----------------
606
607 default = ''
608 class DefaultArg():
609 default = 3
610 def x(self, arg=default):
611 #? str()
612 default
613 return arg
614 def y(self):
615 return default
616
617 #? int()
618 DefaultArg().x()
619 #? str()
620 DefaultArg().y()
621 #? int()
622 DefaultArg.x()
623 #? str()
624 DefaultArg.y()
625
626
627 # -----------------
628 # Error Recovery
629 # -----------------
630
631 from import_tree.pkg.base import MyBase
632
633 class C1(MyBase):
634 def f3(self):
635 #! 13 ['def f1']
636 self.f1() . # hey'''
637 #? 13 MyBase.f1
638 self.f1() . # hey'''
639
640 # -----------------
641 # With a very weird __init__
642 # -----------------
643
644 class WithWeirdInit:
645 class __init__:
646 def __init__(self, a):
647 self.a = a
648
649 def y(self):
650 return self.a
651
652
653 #?
654 WithWeirdInit(1).y()