Skip to content

Commit b678dd4

Browse files
committed
Tell the user which codes they need to add
1 parent a99fd9b commit b678dd4

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

mypy/errors.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -508,9 +508,15 @@ def generate_ignore_without_code_errors(self,
508508
if is_warning_unused_ignores and not used_ignored_lines[line]:
509509
continue
510510

511+
codes_hint = ''
512+
ignored_codes = used_ignored_lines[line]
513+
if ignored_codes:
514+
codes_hint = f' (hint: add [{", ".join(ignored_codes)}])'
515+
516+
message = f'"type: ignore" comment without error code{codes_hint}'
511517
# Don't use report since add_error_info will ignore the error!
512518
info = ErrorInfo(self.import_context(), file, self.current_module(), None,
513-
None, line, -1, 'error', '"type: ignore" comment without error code',
519+
None, line, -1, 'error', message,
514520
None, False, False, False)
515521
self._add_error_info(file, info)
516522

test-data/unit/check-errorcodes.test

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ x # type: ignore[name-defined, attr-defined] # E: Unused "type: ignore[attr-defi
138138
[case testErrorCodeMissingWhenRequired]
139139
# flags: --disallow-ignore-without-code
140140
"x" # type: ignore # E: "type: ignore" comment without error code
141-
y # type: ignore # E: "type: ignore" comment without error code
141+
y # type: ignore # E: "type: ignore" comment without error code (hint: add [name-defined])
142142

143143
[case testErrorCodeMissingDoesntTrampleUnusedIgnoresWarning]
144144
# flags: --disallow-ignore-without-code --warn-unused-ignores

0 commit comments

Comments
 (0)