Skip to content

Commit 82cb7ab

Browse files
committed
Add an error code for this new warning
1 parent 765e1c5 commit 82cb7ab

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

mypy/errorcodes.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,12 @@ def __str__(self) -> str:
133133
NAME_MATCH: Final = ErrorCode(
134134
"name-match", "Check that type definition has consistent naming", "General"
135135
)
136+
IGNORE_WITHOUT_CODE: Final = ErrorCode(
137+
"ignore-without-code",
138+
"Warn about '# type: ignore' comments which do not have error codes",
139+
"General",
140+
default_enabled=False,
141+
)
136142

137143

138144
# Syntax errors are often blocking.

mypy/errors.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -516,8 +516,8 @@ def generate_ignore_without_code_errors(self,
516516
message = f'"type: ignore" comment without error code{codes_hint}'
517517
# Don't use report since add_error_info will ignore the error!
518518
info = ErrorInfo(self.import_context(), file, self.current_module(), None,
519-
None, line, -1, 'error', message,
520-
None, False, False, False)
519+
None, line, -1, 'error', message, codes.IGNORE_WITHOUT_CODE,
520+
False, False, False)
521521
self._add_error_info(file, info)
522522

523523
def num_messages(self) -> int:

test-data/unit/check-errorcodes.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -137,8 +137,8 @@ x # type: ignore[name-defined, attr-defined] # E: Unused "type: ignore[attr-defi
137137

138138
[case testErrorCodeMissingWhenRequired]
139139
# flags: --warn-ignores-without-codes
140-
"x" # type: ignore # E: "type: ignore" comment without error code
141-
y # type: ignore # E: "type: ignore" comment without error code (hint: add [name-defined])
140+
"x" # type: ignore # E: "type: ignore" comment without error code [ignore-without-code]
141+
y # type: ignore # E: "type: ignore" comment without error code (hint: add [name-defined]) [ignore-without-code]
142142

143143
[case testErrorCodeMissingDoesntTrampleUnusedIgnoresWarning]
144144
# flags: --warn-ignores-without-codes --warn-unused-ignores

0 commit comments

Comments
 (0)