@@ -75,41 +75,51 @@ for v in f(): # type: int, int # E: Syntax error in type annotation [syntax]
75
75
76
76
[case testErrorCodeIgnore1]
77
77
'x'.foobar # type: ignore[attr-defined]
78
- 'x'.foobar # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined]
78
+ 'x'.foobar # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined] \
79
+ # N: Error code "attr-defined" not covered by "type: ignore" comment
79
80
'x'.foobar # type: ignore
80
81
81
82
[case testErrorCodeIgnore2]
82
83
a = 'x'.foobar # type: int # type: ignore[attr-defined]
83
- b = 'x'.foobar # type: int # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined]
84
+ b = 'x'.foobar # type: int # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined] \
85
+ # N: Error code "attr-defined" not covered by "type: ignore" comment
84
86
c = 'x'.foobar # type: int # type: ignore
85
87
86
88
[case testErrorCodeIgnore1_python2]
87
89
'x'.foobar # type: ignore[attr-defined]
88
- 'x'.foobar # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined]
90
+ 'x'.foobar # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined] \
91
+ # N: Error code "attr-defined" not covered by "type: ignore" comment
89
92
'x'.foobar # type: ignore
90
93
91
94
[case testErrorCodeIgnore2_python2]
92
95
a = 'x'.foobar # type: int # type: ignore[attr-defined]
93
- b = 'x'.foobar # type: int # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined]
96
+ b = 'x'.foobar # type: int # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined] \
97
+ # N: Error code "attr-defined" not covered by "type: ignore" comment
94
98
c = 'x'.foobar # type: int # type: ignore
95
99
96
100
[case testErrorCodeIgnoreMultiple1]
97
101
a = 'x'.foobar(b) # type: ignore[name-defined, attr-defined]
98
- a = 'x'.foobar(b) # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined]
99
- a = 'x'.foobar(b) # type: ignore[xyz, w, attr-defined] # E: Name "b" is not defined [name-defined]
102
+ a = 'x'.foobar(b) # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined] \
103
+ # N: Error code "attr-defined" not covered by "type: ignore" comment
104
+ a = 'x'.foobar(b) # type: ignore[xyz, w, attr-defined] # E: Name "b" is not defined [name-defined] \
105
+ # N: Error code "name-defined" not covered by "type: ignore" comment
100
106
101
107
[case testErrorCodeIgnoreMultiple2]
102
108
a = 'x'.foobar(b) # type: int # type: ignore[name-defined, attr-defined]
103
- b = 'x'.foobar(b) # type: int # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined]
109
+ b = 'x'.foobar(b) # type: int # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined] \
110
+ # N: Error code "attr-defined" not covered by "type: ignore" comment
104
111
105
112
[case testErrorCodeIgnoreMultiple1_python2]
106
113
a = 'x'.foobar(b) # type: ignore[name-defined, attr-defined]
107
- a = 'x'.foobar(b) # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined]
108
- a = 'x'.foobar(b) # type: ignore[xyz, w, attr-defined] # E: Name "b" is not defined [name-defined]
114
+ a = 'x'.foobar(b) # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined] \
115
+ # N: Error code "attr-defined" not covered by "type: ignore" comment
116
+ a = 'x'.foobar(b) # type: ignore[xyz, w, attr-defined] # E: Name "b" is not defined [name-defined] \
117
+ # N: Error code "name-defined" not covered by "type: ignore" comment
109
118
110
119
[case testErrorCodeIgnoreMultiple2_python2]
111
120
a = 'x'.foobar(b) # type: int # type: ignore[name-defined, attr-defined]
112
- b = 'x'.foobar(b) # type: int # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined]
121
+ b = 'x'.foobar(b) # type: int # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined] \
122
+ # N: Error code "attr-defined" not covered by "type: ignore" comment
113
123
114
124
[case testErrorCodeWarnUnusedIgnores1]
115
125
# flags: --warn-unused-ignores
@@ -140,16 +150,22 @@ x # type: ignore [name-defined]
140
150
x2 # type: ignore [ name-defined ]
141
151
x3 # type: ignore [ xyz , name-defined ]
142
152
x4 # type: ignore[xyz,name-defined]
143
- y # type: ignore [xyz] # E: Name "y" is not defined [name-defined]
144
- y # type: ignore[ xyz ] # E: Name "y" is not defined [name-defined]
145
- y # type: ignore[ xyz , foo ] # E: Name "y" is not defined [name-defined]
153
+ y # type: ignore [xyz] # E: Name "y" is not defined [name-defined] \
154
+ # N: Error code "name-defined" not covered by "type: ignore" comment
155
+ y # type: ignore[ xyz ] # E: Name "y" is not defined [name-defined] \
156
+ # N: Error code "name-defined" not covered by "type: ignore" comment
157
+ y # type: ignore[ xyz , foo ] # E: Name "y" is not defined [name-defined] \
158
+ # N: Error code "name-defined" not covered by "type: ignore" comment
146
159
147
160
a = z # type: int # type: ignore [name-defined]
148
161
b = z2 # type: int # type: ignore [ name-defined ]
149
162
c = z2 # type: int # type: ignore [ name-defined , xyz ]
150
- d = zz # type: int # type: ignore [xyz] # E: Name "zz" is not defined [name-defined]
151
- e = zz # type: int # type: ignore [ xyz ] # E: Name "zz" is not defined [name-defined]
152
- f = zz # type: int # type: ignore [ xyz,foo ] # E: Name "zz" is not defined [name-defined]
163
+ d = zz # type: int # type: ignore [xyz] # E: Name "zz" is not defined [name-defined] \
164
+ # N: Error code "name-defined" not covered by "type: ignore" comment
165
+ e = zz # type: int # type: ignore [ xyz ] # E: Name "zz" is not defined [name-defined] \
166
+ # N: Error code "name-defined" not covered by "type: ignore" comment
167
+ f = zz # type: int # type: ignore [ xyz,foo ] # E: Name "zz" is not defined [name-defined] \
168
+ # N: Error code "name-defined" not covered by "type: ignore" comment
153
169
154
170
[case testErrorCodeIgnoreAfterArgComment]
155
171
def f(x # type: xyz # type: ignore[name-defined] # Comment
@@ -162,7 +178,8 @@ def g(x # type: xyz # type: ignore # Comment
162
178
# type () -> None
163
179
pass
164
180
165
- def h(x # type: xyz # type: ignore[foo] # E: Name "xyz" is not defined [name-defined]
181
+ def h(x # type: xyz # type: ignore[foo] # E: Name "xyz" is not defined [name-defined] \
182
+ # N: Error code "name-defined" not covered by "type: ignore" comment
166
183
):
167
184
# type () -> None
168
185
pass
@@ -178,7 +195,8 @@ def g(x # type: xyz # type: ignore # Comment
178
195
# type () -> None
179
196
pass
180
197
181
- def h(x # type: xyz # type: ignore[foo] # E: Name "xyz" is not defined [name-defined]
198
+ def h(x # type: xyz # type: ignore[foo] # E: Name "xyz" is not defined [name-defined] \
199
+ # N: Error code "name-defined" not covered by "type: ignore" comment
182
200
):
183
201
# type () -> None
184
202
pass
@@ -944,3 +962,20 @@ class TensorType: ...
944
962
t: TensorType["batch":..., float] # type: ignore
945
963
reveal_type(t) # N: Revealed type is "__main__.TensorType"
946
964
[builtins fixtures/tuple.pyi]
965
+
966
+ [case testNoteAboutChangedTypedDictErrorCode]
967
+ from typing_extensions import TypedDict
968
+ class D(TypedDict):
969
+ x: int
970
+
971
+ def f(d: D, s: str) -> None:
972
+ d[s] # type: ignore[xyz] \
973
+ # E: TypedDict key must be a string literal; expected one of ("x") [literal-required] \
974
+ # N: Error code "literal-required" not covered by "type: ignore" comment
975
+ d[s] # E: TypedDict key must be a string literal; expected one of ("x") [literal-required]
976
+ d[s] # type: ignore[misc] \
977
+ # E: TypedDict key must be a string literal; expected one of ("x") [literal-required] \
978
+ # N: Error code changed to literal-required; "type: ignore" comment may be out of date
979
+ d[s] # type: ignore[literal-required]
980
+ [builtins fixtures/dict.pyi]
981
+ [typing fixtures/typing-typeddict.pyi]
0 commit comments