forked from python/mypy
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathcheck-flags.test
242 lines (209 loc) · 5.5 KB
/
check-flags.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
[case testUnannotatedFunction]
# flags: --disallow-untyped-defs
def f(x): pass
[out]
main:2: error: Function is missing a type annotation
[case testUnannotatedArgument]
# flags: --disallow-untyped-defs
def f(x) -> int: pass
[out]
main:2: error: Function is missing a type annotation for one or more arguments
[case testUnannotatedArgumentWithFastParser]
# flags: --fast-parser --disallow-untyped-defs
def f(x) -> int: pass
[out]
main:2: error: Function is missing a type annotation for one or more arguments
[case testNoArgumentFunction]
# flags: --disallow-untyped-defs
def f() -> int: pass
[out]
[case testUnannotatedReturn]
# flags: --disallow-untyped-defs
def f(x: int): pass
[out]
main:2: error: Function is missing a return type annotation
[case testUnannotatedReturnWithFastParser]
# flags: --fast-parser --disallow-untyped-defs
def f(x: int): pass
[out]
main:2: error: Function is missing a return type annotation
[case testLambda]
# flags: --disallow-untyped-defs
lambda x: x
[out]
[case testUntypedDef]
# flags: --disallow-untyped-defs
def f():
1 + "str"
[out]
main:2: error: Function is missing a type annotation
[case testSubclassingAny]
# flags: --disallow-subclassing-any
from typing import Any
FakeClass = None # type: Any
class Foo(FakeClass): pass # E: Class cannot subclass 'FakeClass' (has type 'Any')
[out]
[case testSubclassingAnyMultipleBaseClasses]
# flags: --disallow-subclassing-any
from typing import Any
FakeClass = None # type: Any
class ActualClass: pass
class Foo(ActualClass, FakeClass): pass # E: Class cannot subclass 'FakeClass' (has type 'Any')
[out]
[case testSubclassingAnySilentImports]
# flags: --disallow-subclassing-any --follow-imports=skip
# cmd: mypy -m main
[file main.py]
from ignored_module import BaseClass
class Foo(BaseClass): pass
[file ignored_module.py]
class BaseClass: pass
[out]
tmp/main.py:2: error: Class cannot subclass 'BaseClass' (has type 'Any')
[case testSubclassingAnySilentImports2]
# flags: --disallow-subclassing-any --follow-imports=skip
# cmd: mypy -m main
[file main.py]
import ignored_module
class Foo(ignored_module.BaseClass): pass
[file ignored_module.py]
class BaseClass: pass
[out]
tmp/main.py:2: error: Class cannot subclass 'BaseClass' (has type 'Any')
[case testWarnNoReturnIgnoresTrivialFunctions]
# flags: --warn-no-return
def f() -> int:
pass
def g() -> int:
...
def h() -> int:
"""with docstring"""
pass
def i() -> int:
"""with docstring"""
...
def j() -> int:
u"""with unicode docstring"""
pass
def k() -> int:
"""docstring only"""
[case testWarnNoReturnWorksWithAlwaysTrue]
# flags: --warn-no-return
PY3 = True
def f() -> int:
if PY3:
return 0
else:
return 0
[builtins fixtures/bool.pyi]
[case testWarnNoReturnWorksWithAlwaysFalse]
# flags: --warn-no-return
PY2 = False
def f() -> int:
if PY2:
return 0
else:
return 0
[builtins fixtures/bool.pyi]
[case testWarnNoReturnWorksWithMypyTrue]
# flags: --warn-no-return
MYPY = False
def f() -> int:
if MYPY:
return 0
else:
return 0
[builtins fixtures/bool.pyi]
[case testShowErrorContextFunction]
# flags: --show-error-context
def f() -> None:
0 + ""
[out]
main: note: In function "f":
main:3: error: Unsupported operand types for + ("int" and "str")
[case testShowErrorContextClass]
# flags: --show-error-context
class A:
0 + ""
[out]
main: note: In class "A":
main:3: error: Unsupported operand types for + ("int" and "str")
[case testShowErrorContextMember]
# flags: --show-error-context
class A:
def f(self, x: int) -> None:
self.f("")
[out]
main: note: In member "f" of class "A":
main:4: error: Argument 1 to "f" of "A" has incompatible type "str"; expected "int"
[case testShowErrorContextModule]
# flags: --show-error-context
import m
[file m.py]
0 + ""
[out]
main:2: note: In module imported here:
tmp/m.py:1: error: Unsupported operand types for + ("int" and "str")
[case testShowErrorContextTopLevel]
# flags: --show-error-context
def f() -> None:
0 + ""
0 + ""
[out]
main: note: In function "f":
main:3: error: Unsupported operand types for + ("int" and "str")
main: note: At top level:
main:4: error: Unsupported operand types for + ("int" and "str")
[case testShowErrorContextFromHere]
# flags: --show-error-context
import a
[file a.py]
import b
[file b.py]
0 + ""
[out]
tmp/a.py:1: note: In module imported here,
main:2: note: ... from here:
tmp/b.py:1: error: Unsupported operand types for + ("int" and "str")
[case testFollowImportsNormal]
# flags: --follow-imports=normal
from mod import x
x + ""
[file mod.py]
1 + ""
x = 0
[out]
tmp/mod.py:1: error: Unsupported operand types for + ("int" and "str")
main:3: error: Unsupported operand types for + ("int" and "str")
[case testFollowImportsSilent]
# flags: --follow-imports=silent
from mod import x
x + "" # E: Unsupported operand types for + ("int" and "str")
[file mod.py]
1 + ""
x = 0
[case testFollowImportsSkip]
# flags: --follow-imports=skip
from mod import x
x + ""
[file mod.py]
this deliberate syntax error will not be reported
[out]
[case testFollowImportsError]
# flags: --follow-imports=error
from mod import x
x + ""
[file mod.py]
deliberate syntax error
[out]
main:2: note: Import of 'mod' ignored
main:2: note: (Using --follow-imports=error, module not passed on command line)
[case testIgnoreMissingImportsFalse]
from mod import x
[out]
main:1: error: Cannot find module named 'mod'
main:1: note: (Perhaps setting MYPYPATH or using the "--ignore-missing-imports" flag would help)
[case testIgnoreMissingImportsTrue]
# flags: --ignore-missing-imports
from mod import x
[out]