Skip to content

Commit 400cf02

Browse files
new format for this message, which matches other type: ignores
1 parent bb5ba1a commit 400cf02

File tree

2 files changed

+19
-37
lines changed

2 files changed

+19
-37
lines changed

mypy/errors.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ def add_error_info(self, info: ErrorInfo) -> None:
645645
if ignored_codes and info.code:
646646
# Something is ignored on the line, but not this error, so maybe the error
647647
# code is incorrect.
648-
msg = f'Error code "{info.code.code}" not covered by "type: ignore" comment ignoring [{", ".join(ignored_codes)}]'
648+
msg = f"""Error code "{info.code.code}" not covered by "type: ignore[{', '.join(ignored_codes)}]" comment"""
649649
if info.code in original_error_codes:
650650
# If there seems to be a "type: ignore" with a stale error
651651
# code, report a more specific note.

test-data/unit/check-errorcodes.test

Lines changed: 18 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -60,31 +60,28 @@ for v in x: # type: int, int # type: ignore[syntax]
6060
[case testErrorCodeIgnore1]
6161
'x'.foobar # type: ignore[attr-defined]
6262
'x'.foobar # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined] \
63-
# N: Error code "attr-defined" not covered by "type: ignore" comment ignoring [xyz]
63+
# N: Error code "attr-defined" not covered by "type: ignore[xyz]" comment
6464
'x'.foobar # type: ignore
6565

66-
6766
[case testErrorCodeIgnore2]
6867
a = 'x'.foobar # type: int # type: ignore[attr-defined]
6968
b = 'x'.foobar # type: int # type: ignore[xyz] # E: "str" has no attribute "foobar" [attr-defined] \
70-
# N: Error code "attr-defined" not covered by "type: ignore" comment ignoring [xyz]
69+
# N: Error code "attr-defined" not covered by "type: ignore[xyz]" comment
7170
c = 'x'.foobar # type: int # type: ignore
7271

73-
7472
[case testErrorCodeIgnoreMultiple1]
7573
a = 'x'.foobar(b) # type: ignore[name-defined, attr-defined]
7674
a = 'x'.foobar(b) # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined] \
77-
# N: Error code "attr-defined" not covered by "type: ignore" comment ignoring [name-defined, xyz]
75+
# N: Error code "attr-defined" not covered by "type: ignore[name-defined, xyz]" comment
7876
a = 'x'.foobar(b) # type: ignore[xyz, w, attr-defined] # E: Name "b" is not defined [name-defined] \
79-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [xyz, w, attr-defined]
80-
81-
77+
# N: Error code "name-defined" not covered by "type: ignore[xyz, w, attr-defined]" comment
78+
a = 'x'.foobar(b) # type: ignore[ w, xyz, attr-defined] # E: Name "b" is not defined [name-defined] \
79+
# N: Error code "name-defined" not covered by "type: ignore[w, xyz, attr-defined]" comment
8280

8381
[case testErrorCodeIgnoreMultiple2]
8482
a = 'x'.foobar(c) # type: int # type: ignore[name-defined, attr-defined]
8583
b = 'x'.foobar(c) # type: int # type: ignore[name-defined, xyz] # E: "str" has no attribute "foobar" [attr-defined] \
86-
# N: Error code "attr-defined" not covered by "type: ignore" comment ignoring [name-defined, xyz]
87-
84+
# N: Error code "attr-defined" not covered by "type: ignore[name-defined, xyz]" comment
8885

8986
[case testErrorCodeWarnUnusedIgnores1]
9087
# flags: --warn-unused-ignores
@@ -136,9 +133,7 @@ z # type: ignore[name-defined]
136133
"y" # type: ignore[ignore-without-code] # E: Unused "type: ignore" comment [unused-ignore]
137134
z # type: ignore[ignore-without-code] # E: Unused "type: ignore" comment [unused-ignore] \
138135
# E: Name "z" is not defined [name-defined] \
139-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [ignore-without-code]
140-
141-
136+
# N: Error code "name-defined" not covered by "type: ignore[ignore-without-code]" comment
142137

143138
[case testErrorCodeMissingWholeFileIgnores]
144139
# flags: --enable-error-code ignore-without-code
@@ -164,27 +159,21 @@ x2 # type: ignore [ name-defined ]
164159
x3 # type: ignore [ xyz , name-defined ]
165160
x4 # type: ignore[xyz,name-defined]
166161
y # type: ignore [xyz] # E: Name "y" is not defined [name-defined] \
167-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [xyz]
162+
# N: Error code "name-defined" not covered by "type: ignore[xyz]" comment
168163
y # type: ignore[ xyz ] # E: Name "y" is not defined [name-defined] \
169-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [xyz]
164+
# N: Error code "name-defined" not covered by "type: ignore[xyz]" comment
170165
y # type: ignore[ xyz , foo ] # E: Name "y" is not defined [name-defined] \
171-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [xyz, foo]
166+
# N: Error code "name-defined" not covered by "type: ignore[xyz, foo]" comment
172167

173168
a = z # type: int # type: ignore [name-defined]
174169
b = z2 # type: int # type: ignore [ name-defined ]
175170
c = z2 # type: int # type: ignore [ name-defined , xyz ]
176171
d = zz # type: int # type: ignore [xyz] # E: Name "zz" is not defined [name-defined] \
177-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [xyz]
172+
# N: Error code "name-defined" not covered by "type: ignore[xyz]" comment
178173
e = zz # type: int # type: ignore [ xyz ] # E: Name "zz" is not defined [name-defined] \
179-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [xyz]
174+
# N: Error code "name-defined" not covered by "type: ignore[xyz]" comment
180175
f = zz # type: int # type: ignore [ xyz,foo ] # E: Name "zz" is not defined [name-defined] \
181-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [xyz, foo]
182-
183-
184-
185-
186-
187-
176+
# N: Error code "name-defined" not covered by "type: ignore[xyz, foo]" comment
188177

189178
[case testErrorCodeIgnoreAfterArgComment]
190179
def f(x # type: xyz # type: ignore[name-defined] # Comment
@@ -198,12 +187,11 @@ def g(x # type: xyz # type: ignore # Comment
198187
pass
199188

200189
def h(x # type: xyz # type: ignore[foo] # E: Name "xyz" is not defined [name-defined] \
201-
# N: Error code "name-defined" not covered by "type: ignore" comment ignoring [foo]
190+
# N: Error code "name-defined" not covered by "type: ignore[foo]" comment
202191
):
203192
# type () -> None
204193
pass
205194

206-
207195
[case testErrorCodeIgnoreWithNote]
208196
import nostub # type: ignore[import]
209197
from defusedxml import xyz # type: ignore[import]
@@ -1026,30 +1014,24 @@ class D(TypedDict):
10261014

10271015
def f(d: D, s: str) -> None:
10281016
d[s] # type: ignore[xyz] # E: TypedDict key must be a string literal; expected one of ("x") [literal-required] \
1029-
# N: Error code "literal-required" not covered by "type: ignore" comment ignoring [xyz]
1017+
# N: Error code "literal-required" not covered by "type: ignore[xyz]" comment
10301018
d[s] # E: TypedDict key must be a string literal; expected one of ("x") [literal-required]
10311019
d[s] # type: ignore[misc] # E: TypedDict key must be a string literal; expected one of ("x") [literal-required] \
10321020
# N: Error code changed to literal-required; "type: ignore" comment may be out of date
10331021
d[s] # type: ignore[literal-required]
1034-
1035-
1036-
1037-
10381022
[builtins fixtures/dict.pyi]
10391023
[typing fixtures/typing-typeddict.pyi]
10401024

10411025
[case testRecommendErrorCode]
10421026
# type: ignore[whatever] # E: type ignore with error code is not supported for modules; use `# mypy: disable-error-code="whatever"` [syntax] \
1043-
# N: Error code "syntax" not covered by "type: ignore" comment ignoring [whatever]
1027+
# N: Error code "syntax" not covered by "type: ignore[whatever]" comment
10441028
1 + "asdf"
10451029

1046-
10471030
[case testRecommendErrorCode2]
10481031
# type: ignore[whatever, other] # E: type ignore with error code is not supported for modules; use `# mypy: disable-error-code="whatever, other"` [syntax] \
1049-
# N: Error code "syntax" not covered by "type: ignore" comment ignoring [whatever, other]
1032+
# N: Error code "syntax" not covered by "type: ignore[whatever, other]" comment
10501033
1 + "asdf"
10511034

1052-
10531035
[case testShowErrorCodesInConfig]
10541036
# flags: --config-file tmp/mypy.ini
10551037
# Test 'show_error_codes = True' in config doesn't raise an exception

0 commit comments

Comments
 (0)