Debian Codegraph @

test/completion/precedence.py

raw symbols SCIP
1 """
2 Test Jedi's operation understanding. Jedi should understand simple additions,
3 multiplications, etc.
4 """
5 # -----------------
6 # numbers
7 # -----------------
8 x = [1, 'a', 1.0]
9
10 #? int() str() float()
11 x[12]
12
13 #? float()
14 x[1 + 1]
15
16 index = 0 + 1
17
18 #? str()
19 x[index]
20
21 #? int()
22 x[1 + (-1)]
23
24 def calculate(number):
25 return number + constant
26
27 constant = 1
28
29 #? float()
30 x[calculate(1)]
31
32 def calculate(number):
33 return number + constant
34
35 # -----------------
36 # strings
37 # -----------------
38
39 x = 'upp' + 'e'
40
41 #? str.upper
42 getattr(str, x + 'r')
43
44 a = "a"*3
45 #? str()
46 a
47 a = 3 * "a"
48 #? str()
49 a
50
51 a = 3 * "a"
52 #? str()
53 a
54
55 #? int()
56 (3 ** 3)
57 #? int() float()
58 (3 ** 'a')
59 #? int()
60 (3 + 'a')
61 #? bool()
62 (3 == 'a')
63 #? bool()
64 (3 >= 'a')
65
66 class X():
67 foo = 2
68 #? int()
69 (X.foo ** 3)
70
71 # -----------------
72 # assignments
73 # -----------------
74
75 x = [1, 'a', 1.0]
76
77 i = 0
78 i += 1
79 i += 1
80 #? float()
81 x[i]
82
83 i = 1
84 i += 1
85 i -= 3
86 i += 1
87 #? int()
88 x[i]
89
90 # -----------------
91 # in
92 # -----------------
93
94 if 'X' in 'Y':
95 a = 3
96 else:
97 a = ''
98 # For now don't really check for truth values. So in should return both
99 # results.
100 #? str() int()
101 a
102
103 if 'X' not in 'Y':
104 b = 3
105 else:
106 b = ''
107 # For now don't really check for truth values. So in should return both
108 # results.
109 #? str() int()
110 b
111
112 # -----------------
113 # for flow assignments
114 # -----------------
115
116 class FooBar(object):
117 fuu = 0.1
118 raboof = 'fourtytwo'
119
120 # targets should be working
121 target = ''
122 for char in ['f', 'u', 'u']:
123 target += char
124 #? float()
125 getattr(FooBar, target)
126
127 # github #24
128 target = u''
129 for char in reversed(['f', 'o', 'o', 'b', 'a', 'r']):
130 target += char
131
132 #? str()
133 getattr(FooBar, target)
134
135
136 # -----------------
137 # repetition problems -> could be very slow and memory expensive - shouldn't
138 # be.
139 # -----------------
140
141 b = [str(1)]
142 l = list
143 for x in [l(0), l(1), l(2), l(3), l(4), l(5), l(6), l(7), l(8), l(9), l(10),
144 l(11), l(12), l(13), l(14), l(15), l(16), l(17), l(18), l(19), l(20),
145 l(21), l(22), l(23), l(24), l(25), l(26), l(27), l(28), l(29)]:
146 b += x
147
148 #? str()
149 b[1]
150
151
152 # -----------------
153 # undefined names
154 # -----------------
155 a = foobarbaz + 'hello'
156
157 #? int() float()
158 {'hello': 1, 'bar': 1.0}[a]
159
160 # -----------------
161 # stubs
162 # -----------------
163
164 from datetime import datetime, timedelta
165
166 #?
167 (datetime - timedelta)
168 #? datetime()
169 (datetime() - timedelta())
170 #? timedelta() datetime()
171 (datetime() - datetime())
172 #? timedelta()
173 (timedelta() - datetime())
174 #? timedelta()
175 (timedelta() - timedelta())
176
177 # -----------------
178 # magic methods
179 # -----------------
180
181 class C:
182 def __sub__(self, other) -> int: ...
183 def __radd__(self, other) -> float: ...
184
185 #? int()
186 (C() - object())
187 #? C() object()
188 (object() - C())
189 #? C() object()
190 (C() + object())
191 #? float()
192 (object() + C())