@@ -20,38 +20,42 @@ def g(arg): ...
20
20
def f(a, b=2): ...
21
21
def g(b=-1, c=0): ...
22
22
[out]
23
- def f(a, b=2 ): ...
24
- def g(b=-1 , c=0 ): ...
23
+ def f(a, b: int = ... ): ...
24
+ def g(b: int = ... , c: int = ... ): ...
25
25
26
26
[case testDefaultArgNone]
27
27
def f(x=None): ...
28
28
[out]
29
- def f(x=None): ...
29
+ from typing import Any, Optional
30
+
31
+ def f(x: Optional[Any] = ...): ...
30
32
31
33
[case testDefaultArgBool]
32
34
def f(x=True, y=False): ...
33
35
[out]
34
- def f(x=True , y=False ): ...
36
+ def f(x: bool = ... , y: bool = ... ): ...
35
37
36
38
[case testDefaultArgStr]
37
39
def f(x='foo'): ...
38
40
[out]
39
- def f(x='' ): ...
41
+ def f(x: str = ... ): ...
40
42
41
43
[case testDefaultArgBytes]
42
44
def f(x=b'foo'): ...
43
45
[out]
44
- def f(x=b'' ): ...
46
+ def f(x: bytes = ... ): ...
45
47
46
48
[case testDefaultArgFloat]
47
49
def f(x=1.2): ...
48
50
[out]
49
- def f(x=0.0 ): ...
51
+ def f(x: float = ... ): ...
50
52
51
53
[case testDefaultArgOther]
52
54
def f(x=ord): ...
53
55
[out]
54
- def f(x=...): ...
56
+ from typing import Any
57
+
58
+ def f(x: Any = ...): ...
55
59
56
60
[case testVarArgs]
57
61
def f(x, *y): ...
@@ -77,38 +81,30 @@ def g(): ...
77
81
[case testVariable]
78
82
x = 1
79
83
[out]
80
- from typing import Any
81
-
82
- x = ... # type: Any
84
+ x = ... # type: int
83
85
84
86
[case testMultipleVariable]
85
87
x = y = 1
86
88
[out]
87
- from typing import Any
88
-
89
- x = ... # type: Any
90
- y = ... # type: Any
89
+ x = ... # type: int
90
+ y = ... # type: int
91
91
92
92
[case testClassVariable]
93
93
class C:
94
94
x = 1
95
95
[out]
96
- from typing import Any
97
-
98
96
class C:
99
- x = ... # type: Any
97
+ x = ... # type: int
100
98
101
99
[case testSelfAssignment]
102
100
class C:
103
101
def __init__(self):
104
102
self.x = 1
105
103
x.y = 2
106
104
[out]
107
- from typing import Any
108
-
109
105
class C:
110
- x = ... # type: Any
111
- def __init__(self): ...
106
+ x = ... # type: int
107
+ def __init__(self) -> None : ...
112
108
113
109
[case testSelfAndClassBodyAssignment]
114
110
x = 1
@@ -118,13 +114,11 @@ class C:
118
114
self.x = 1
119
115
self.x = 1
120
116
[out]
121
- from typing import Any
122
-
123
- x = ... # type: Any
117
+ x = ... # type: int
124
118
125
119
class C:
126
- x = ... # type: Any
127
- def __init__(self): ...
120
+ x = ... # type: int
121
+ def __init__(self) -> None : ...
128
122
129
123
[case testEmptyClass]
130
124
class A: ...
@@ -189,8 +183,8 @@ y = ... # type: Any
189
183
def f(x, *, y=1): ...
190
184
def g(x, *, y=1, z=2): ...
191
185
[out]
192
- def f(x, *, y=1 ): ...
193
- def g(x, *, y=1 , z=2 ): ...
186
+ def f(x, *, y: int = ... ): ...
187
+ def g(x, *, y: int = ... , z: int = ... ): ...
194
188
195
189
[case testProperty]
196
190
class A:
@@ -311,10 +305,8 @@ class A:
311
305
x = 1
312
306
def f(self): ...
313
307
[out]
314
- from typing import Any
315
-
316
308
class A:
317
- x = ... # type: Any
309
+ x = ... # type: int
318
310
def f(self): ...
319
311
320
312
[case testMultiplePrivateDefs]
@@ -332,32 +324,29 @@ from re import match, search, sub
332
324
__all__ = ['match', 'sub', 'x']
333
325
x = 1
334
326
[out]
335
- from typing import Any
336
327
from re import match as match, sub as sub
337
328
338
- x = ... # type: Any
329
+ x = ... # type: int
339
330
340
331
[case testExportModule_import]
341
332
import re
342
333
__all__ = ['re', 'x']
343
334
x = 1
344
335
y = 2
345
336
[out]
346
- from typing import Any
347
337
import re as re
348
338
349
- x = ... # type: Any
339
+ x = ... # type: int
350
340
351
341
[case testExportModuleAs_import]
352
342
import re as rex
353
343
__all__ = ['rex', 'x']
354
344
x = 1
355
345
y = 2
356
346
[out]
357
- from typing import Any
358
347
import re as rex
359
348
360
- x = ... # type: Any
349
+ x = ... # type: int
361
350
362
351
[case testExportModuleInPackage_import]
363
352
import urllib.parse as p
@@ -384,11 +373,9 @@ x = 1
384
373
class C:
385
374
def g(self): ...
386
375
[out]
387
- from typing import Any
388
-
389
376
def f(): ...
390
377
391
- x = ... # type: Any
378
+ x = ... # type: int
392
379
393
380
class C:
394
381
def g(self): ...
@@ -521,11 +508,9 @@ class A:
521
508
def f(self): ...
522
509
def g(self): ...
523
510
[out]
524
- from typing import Any
525
-
526
511
class A:
527
512
class B:
528
- x = ... # type: Any
513
+ x = ... # type: int
529
514
def f(self): ...
530
515
def g(self): ...
531
516
0 commit comments