@@ -163,6 +163,55 @@ from defusedxml import xyz # type: ignore[import]
163
163
import nostub # type: ignore[import]
164
164
from defusedxml import xyz # type: ignore[import]
165
165
166
+ [case testErrorCodeBadIgnore]
167
+ import nostub # type: ignore xyz # E: Invalid "type: ignore" comment [syntax]
168
+ import nostub # type: ignore[ # E: Invalid "type: ignore" comment [syntax]
169
+ import nostub # type: ignore[foo # E: Invalid "type: ignore" comment [syntax]
170
+ import nostub # type: ignore[foo, # E: Invalid "type: ignore" comment [syntax]
171
+ import nostub # type: ignore[foo]] # E: Invalid "type: ignore" comment [syntax]
172
+ import nostub # type: ignore[foo][bar] # E: Invalid "type: ignore" comment [syntax]
173
+ import nostub # type: ignore[foo] [bar] # E: Invalid "type: ignore" comment [syntax]
174
+
175
+ x = 0 # type: ignore[ # E: Invalid "type: ignore" comment [syntax]
176
+
177
+ def f(x, # type: int # type: ignore[ # E: Invalid "type: ignore" comment [syntax]
178
+ ):
179
+ # type: (...) -> None
180
+ pass
181
+
182
+ [case testErrorCodeBadIgnoreNoExtraComment]
183
+ # Omit the E: ... comments, as they affect parsing
184
+ import nostub # type: ignore xyz
185
+ import nostub # type: ignore[xyz
186
+ import nostub # type: ignore[xyz][xyz]
187
+ x = 0 # type: ignore[
188
+ def f(x, # type: int # type: ignore[
189
+ ):
190
+ # type: (...) -> None
191
+ pass
192
+ [out]
193
+ main:2: error: Invalid "type: ignore" comment [syntax]
194
+ main:3: error: Invalid "type: ignore" comment [syntax]
195
+ main:4: error: Invalid "type: ignore" comment [syntax]
196
+ main:5: error: Invalid "type: ignore" comment [syntax]
197
+ main:6: error: Invalid "type: ignore" comment [syntax]
198
+
199
+ [case testErrorCodeBadIgnore_python2]
200
+ import nostub # type: ignore xyz
201
+ import nostub # type: ignore[xyz # Comment [x]
202
+ import nostub # type: ignore[xyz][xyz]
203
+ x = 0 # type: ignore[
204
+ def f(x, # type: int # type: ignore[
205
+ ):
206
+ # type: (...) -> None
207
+ pass
208
+ [out]
209
+ main:1: error: Invalid "type: ignore" comment [syntax]
210
+ main:2: error: Invalid "type: ignore" comment [syntax]
211
+ main:3: error: Invalid "type: ignore" comment [syntax]
212
+ main:4: error: Invalid "type: ignore" comment [syntax]
213
+ main:5: error: Invalid "type: ignore" comment [syntax]
214
+
166
215
[case testErrorCodeArgKindAndCount]
167
216
def f(x: int) -> None: pass # N: "f" defined here
168
217
f() # E: Too few arguments for "f" [call-arg]
@@ -607,3 +656,19 @@ class A:
607
656
def g(self: A) -> None: pass
608
657
609
658
A.f = g # E: Cannot assign to a method [assignment]
659
+
660
+ [case testErrorCodeTypeIgnoreMisspelled1]
661
+ x = y # type: ignored[foo]
662
+ xx = y # type: ignored [foo]
663
+ [out]
664
+ main:1: error: Name 'ignored' is not defined [name-defined]
665
+ main:1: error: Name 'y' is not defined [name-defined]
666
+ main:2: error: Name 'ignored' is not defined [name-defined]
667
+ main:2: error: Name 'y' is not defined [name-defined]
668
+
669
+ [case testErrorCodeTypeIgnoreMisspelled2]
670
+ x = y # type: int # type: ignored[foo]
671
+ x = y # type: int # type: ignored [foo]
672
+ [out]
673
+ main:1: error: syntax error in type comment 'int' [syntax]
674
+ main:2: error: syntax error in type comment 'int' [syntax]
0 commit comments