File tree Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Expand file tree Collapse file tree 2 files changed +34
-1
lines changed Original file line number Diff line number Diff line change @@ -1564,9 +1564,11 @@ def expect_type(self, typ: type) -> Token:
1564
1564
def expect_colon_and_break (self ) -> Tuple [Token , Token ]:
1565
1565
return self .expect_type (Colon ), self .expect_type (Break )
1566
1566
1567
+ type_ignore_exp = re .compile (r'[ \t]*#[ \t]*type:[ \t]*ignore\b' )
1568
+
1567
1569
def expect_break (self ) -> Token :
1568
1570
token = self .expect_type (Break )
1569
- if '# type: ignore' in token .pre :
1571
+ if re . match ( self . type_ignore_exp , token .pre ) :
1570
1572
self .ignored_lines .add (token .line )
1571
1573
return token
1572
1574
Original file line number Diff line number Diff line change @@ -3261,3 +3261,34 @@ MypyFile:1(
3261
3261
ExpressionStmt:3(
3262
3262
NameExpr(z))
3263
3263
IgnoredLines(2, 3))
3264
+
3265
+ [case testCommentedOutIgnoreAnnotation]
3266
+ y ## type: ignore
3267
+ [out]
3268
+ MypyFile:1(
3269
+ ExpressionStmt:1(
3270
+ NameExpr(y)))
3271
+
3272
+ [case testInvalidIgnoreAnnotations]
3273
+ y # type: ignored
3274
+ y # type: IGNORE
3275
+ y # type : ignore
3276
+ [out]
3277
+ MypyFile:1(
3278
+ ExpressionStmt:1(
3279
+ NameExpr(y))
3280
+ ExpressionStmt:2(
3281
+ NameExpr(y))
3282
+ ExpressionStmt:3(
3283
+ NameExpr(y)))
3284
+
3285
+ [case testSpaceInIgnoreAnnotations]
3286
+ y # type: ignore # foo
3287
+ y #type:ignore
3288
+ [out]
3289
+ MypyFile:1(
3290
+ ExpressionStmt:1(
3291
+ NameExpr(y))
3292
+ ExpressionStmt:2(
3293
+ NameExpr(y))
3294
+ IgnoredLines(1, 2))
You can’t perform that action at this time.
0 commit comments