forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathdeps-expressions.test
466 lines (401 loc) · 8.44 KB
/
deps-expressions.test
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
-- Test cases for generating fine-grained dependencies for expressions.
--
-- The dependencies are used for fined-grained incremental checking.
--
-- See the comment at the top of deps.test for more documentation.
[case testListExpr]
def f() -> int: pass
def g() -> None:
a = [f()]
[builtins fixtures/list.pyi]
[out]
<m.f> -> m.g
[case testDictExpr]
def f1() -> int: pass
def f2() -> int: pass
def g() -> None:
a = {f1(): 1, 2: f2()}
[builtins fixtures/dict.pyi]
[out]
<m.f1> -> m.g
<m.f2> -> m.g
[case testSetExpr]
def f() -> int: pass
def g() -> None:
a = {f()}
[builtins fixtures/set.pyi]
[out]
<m.f> -> m.g
[case testTupleExpr]
def f1() -> int: pass
def f2() -> int: pass
def g() -> None:
a = (f1(), f2())
[builtins fixtures/tuple.pyi]
[out]
<m.f1> -> m.g
<m.f2> -> m.g
[case testListComprehension]
from typing import Iterator
class A:
def __iter__(self) -> Iterator[int]: pass
def f1() -> int: pass
def f2() -> int: pass
def g() -> None:
a = [f1() for x in A() if f2()]
[builtins fixtures/list.pyi]
[out]
<m.A.__init__> -> m.g
<m.A.__iter__> -> m.g
<m.A.__new__> -> m.g
<m.A> -> m.A, m.g
<m.f1> -> m.g
<m.f2> -> m.g
[case testSetComprehension]
from typing import Set
def f1() -> int: pass
def f2() -> Set[int]: pass
def f3() -> int: pass
def g() -> None:
a = {f1() for x in f2() if f3()}
[builtins fixtures/set.pyi]
[out]
<m.f1> -> m.g
<m.f2> -> m.g
<m.f3> -> m.g
[case testDictComprehension]
from typing import Iterator
class A:
def __iter__(self) -> Iterator[int]: pass
def f1() -> int: pass
def f2() -> int: pass
def f3() -> int: pass
def g() -> None:
a = {f1(): f2() for x in A() if f3()}
[builtins fixtures/dict.pyi]
[out]
<m.A.__init__> -> m.g
<m.A.__iter__> -> m.g
<m.A.__new__> -> m.g
<m.A> -> m.A, m.g
<m.f1> -> m.g
<m.f2> -> m.g
<m.f3> -> m.g
[case testGeneratorExpr]
from typing import List
def f1() -> int: pass
def f2() -> List[int]: pass
def f3() -> int: pass
def g() -> None:
a = (f1() for x in f2() if f3())
[builtins fixtures/list.pyi]
[out]
<m.f1> -> m.g
<m.f2> -> m.g
<m.f3> -> m.g
[case testConditionalExpr]
def f1() -> int: pass
def f2() -> int: pass
def f3() -> int: pass
def g() -> None:
a = f1() if f2() else f3()
[out]
<m.f1> -> m.g
<m.f2> -> m.g
<m.f3> -> m.g
[case testAwaitExpr]
def f(): pass
async def g() -> None:
x = await f()
[builtins fixtures/async_await.pyi]
[typing fixtures/typing-full.pyi]
[out]
<m.f> -> m.g
[case testStarExpr]
from typing import Iterator
class A:
def __iter__(self) -> Iterator[int]: pass
def g() -> None:
a = [*A()]
[builtins fixtures/list.pyi]
[out]
<m.A.__init__> -> m.g
<m.A.__iter__> -> <m.A>, m.g
<m.A.__new__> -> m.g
<m.A> -> m.A, m.g, typing.Iterable
[case testCast]
from typing import cast
class A: pass
def f() -> object: pass
def g() -> None:
x = cast(A, f())
[out]
<m.A> -> m.A, m.g
<m.f> -> m.g
[case testTypeApplication]
from typing import TypeVar, Generic
T = TypeVar('T')
S = TypeVar('S')
class A(Generic[T, S]):
def __init__(self, x): pass
class B: pass
class C: pass
def f() -> int: pass
def g() -> None:
x = A[B, C](f())
[out]
<m.A.__init__> -> m.g
<m.A.__new__> -> m.g
<m.A> -> m.A, m.g
<m.B> -> m.B, m.g
<m.C> -> m.C, m.g
<m.S> -> m.A
<m.T> -> m.A
<m.f> -> m.g
[case testIndexExpr]
class A:
def __getitem__(self, x: int) -> int: pass
def f1() -> A: pass
def f2() -> int: pass
def g(a: A) -> int:
return f1()[f2()]
[out]
<m.A.__getitem__> -> m.g
<m.A> -> <m.f1>, <m.g>, m.A, m.f1, m.g
<m.f1> -> m.g
<m.f2> -> m.g
[case testIndexExpr]
class A:
def __getitem__(self, x: int) -> int: pass
def f1() -> A: pass
def f2() -> int: pass
def g(a: A) -> int:
return f1()[f2()]
[out]
<m.A.__getitem__> -> m.g
<m.A> -> <m.f1>, <m.g>, m.A, m.f1, m.g
<m.f1> -> m.g
<m.f2> -> m.g
[case testIndexExprLvalue]
class A:
def __setitem__(self, x: int, y: int) -> None: pass
def f1() -> A: pass
def f2() -> int: pass
def f3() -> int: pass
def g(a: A) -> None:
f1()[f2()] = f3()
[out]
-- __getitem__ dependency is redundant but harmless
<m.A.__getitem__> -> m.g
<m.A.__setitem__> -> m.g
<m.A> -> <m.f1>, <m.g>, m.A, m.f1, m.g
<m.f1> -> m.g
<m.f2> -> m.g
<m.f3> -> m.g
[case testUnaryExpr]
class A:
def __neg__(self) -> int: pass
def __pos__(self) -> int: pass
def __invert__(self) -> int: pass
def f1() -> A: pass
def f2() -> A: pass
def f3() -> A: pass
def g1() -> int:
return +f1()
def g2() -> int:
return -f2()
def g3() -> int:
return ~f3()
[out]
<m.A.__invert__> -> m.g3
<m.A.__neg__> -> m.g2
<m.A.__pos__> -> m.g1
<m.A> -> <m.f1>, <m.f2>, <m.f3>, m.A, m.f1, m.f2, m.f3
<m.f1> -> m.g1
<m.f2> -> m.g2
<m.f3> -> m.g3
[case testOpExpr]
class A:
def __add__(self, x: 'B') -> int: pass
class B: pass
def f() -> int:
a: A
b: B
return a + b
[out]
<m.A.__add__> -> m.f
<m.A> -> m.A, m.f
<m.B.__radd__> -> m.f
<m.B> -> <m.A.__add__>, m.A.__add__, m.B, m.f
[case testComparisonExpr]
class A:
def __lt__(self, x: 'B') -> int: pass
class B: pass
def f() -> int:
return A() < B()
[out]
<m.A.__init__> -> m.f
<m.A.__lt__> -> m.f
<m.A.__new__> -> m.f
<m.A> -> m.A, m.f
<m.B.__gt__> -> m.f
<m.B.__init__> -> m.f
<m.B.__new__> -> m.f
<m.B> -> <m.A.__lt__>, m.A.__lt__, m.B, m.f
[case testIsOp-skip]
class A: pass
class B: pass
def f() -> bool:
return A() is B()
[builtins fixtures/bool.pyi]
[out]
-- fails because of https://github.com/python/mypy/issues/4055
<m.A.__init__> -> m.f
<m.A.__new__> -> m.f
<m.A> -> m.A, m.f
<m.B.__init__> -> m.f
<m.B.__new__> -> m.f
<m.B> -> m.B, m.f
[case testInOp]
class A:
def __contains__(self, x: B) -> int: pass
class B: pass
def f() -> bool:
return B() in A()
[builtins fixtures/bool.pyi]
[out]
<m.A.__contains__> -> m.f
<m.A.__init__> -> m.f
<m.A.__new__> -> m.f
<m.A> -> m.A, m.f
<m.B.__init__> -> m.f
<m.B.__new__> -> m.f
<m.B> -> <m.A.__contains__>, m.A.__contains__, m.B, m.f
[case testComparisonExprWithMultipleOperands]
class A:
def __lt__(self, x: 'B') -> int: pass
class B: pass
class C:
def __ge__(self, x: 'B') -> int: pass
def f() -> int:
return A() < B() <= C()
[out]
<m.A.__init__> -> m.f
<m.A.__lt__> -> m.f
<m.A.__new__> -> m.f
<m.A> -> m.A, m.f
<m.B.__gt__> -> m.f
<m.B.__init__> -> m.f
<m.B.__le__> -> m.f
<m.B.__new__> -> m.f
<m.B> -> <m.A.__lt__>, <m.C.__ge__>, m.A.__lt__, m.B, m.C.__ge__, m.f
<m.C.__ge__> -> m.f
<m.C.__init__> -> m.f
<m.C.__new__> -> m.f
<m.C> -> m.C, m.f
[case testOperatorWithTupleOperand]
from typing import Tuple
class C(Tuple[int, str]):
def __and__(self, x: D) -> int: pass
def __neg__(self) -> int: pass
class D: pass
def f() -> None:
c: C
d: D
x = c & d
y = -c
[builtins fixtures/tuple.pyi]
[out]
<m.C.__and__> -> m.f
<m.C.__neg__> -> m.f
<m.C> -> m.C, m.f
<m.D.__rand__> -> m.f
<m.D> -> <m.C.__and__>, m.C.__and__, m.D, m.f
[case testUnionTypeOperation]
from typing import Union
class A:
def __add__(self, x: str) -> int: pass
class B:
def __add__(self, x: str) -> int: pass
def f(a: Union[A, B]) -> int:
return a + ''
[out]
<m.A.__add__> -> m.f
<m.A> -> <m.f>, m.A, m.f
<m.B.__add__> -> m.f
<m.B> -> <m.f>, m.B, m.f
[case testBackquoteExpr_python2]
def g(): # type: () -> int
pass
def f(): # type: () -> str
return `g()`
[out]
<m.g> -> m.f
[case testComparison_python2]
class A:
def __cmp__(self, other): # type: (B) -> int
pass
class B:
pass
def f(a, b): # type: (A, B) -> None
x = a == b
def g(a, b): # type: (A, B) -> None
x = a < b
[out]
<m.A.__cmp__> -> m.f, m.g
<m.A.__eq__> -> m.f
<m.A.__lt__> -> m.g
<m.A> -> <m.f>, <m.g>, m.A, m.f, m.g
<m.B.__cmp__> -> m.f, m.g
<m.B.__eq__> -> m.f
<m.B.__gt__> -> m.g
<m.B> -> <m.A.__cmp__>, <m.f>, <m.g>, m.A.__cmp__, m.B, m.f, m.g
[case testSliceExpr]
class A:
def __getitem__(self, x) -> None: pass
def f1() -> int: pass
def f2() -> int: pass
def f3() -> int: pass
def f4() -> int: pass
def f5() -> int: pass
def f() -> None:
a: A
a[f1():f2():f3()]
a[f4():]
a[::f5()]
[builtins fixtures/slice.pyi]
[out]
<m.A.__getitem__> -> m.f
<m.A> -> m.A, m.f
<m.f1> -> m.f
<m.f2> -> m.f
<m.f3> -> m.f
<m.f4> -> m.f
<m.f5> -> m.f
[case testRevealTypeExpr]
def f1() -> int: pass
def f() -> None:
reveal_type(f1()) # type: ignore
[out]
<m.f1> -> m.f
[case testLambdaExpr]
from typing import Callable
def f1(c: Callable[[int], str]) -> None: pass
def f2() -> str: pass
def g() -> None:
f1(lambda x: f2())
[out]
<m.f1> -> m.g
<m.f2> -> m.g
[case testLiteralDepsExpr]
from typing_extensions import Literal
Alias = Literal[1]
a: Alias
b = a
def f(x: Alias) -> None: pass
def g() -> Literal[1]:
return b
[out]
<m.Alias> -> m, m.f
<m.a> -> m
<m.b> -> m, m.g