Skip to content

Commit

Permalink
Tweak error message to avoid misleading the user
Browse files Browse the repository at this point in the history
Users who turn ignore-without-code on are likely at first to
encounter cases where their existing ignores are too broad.
The previous hint spelling was useful, however could encourage
users to just ignore everything which was already ignored rather
than actually reviewing the code. This change removes the implication
that the correct course is to blindly update the ignore comment
while still containing the useful information about what is ignored.
  • Loading branch information
PeterJCLaw committed Dec 18, 2021
1 parent 223da4b commit 6f39906
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 2 deletions.
2 changes: 1 addition & 1 deletion mypy/errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -511,7 +511,7 @@ def generate_ignore_without_code_errors(self,
codes_hint = ''
ignored_codes = used_ignored_lines[line]
if ignored_codes:
codes_hint = f' (hint: add [{", ".join(ignored_codes)}])'
codes_hint = f' (currently ignored: [{", ".join(ignored_codes)}])'

message = f'"type: ignore" comment without error code{codes_hint}'
# Don't use report since add_error_info will ignore the error!
Expand Down
2 changes: 1 addition & 1 deletion test-data/unit/check-errorcodes.test
Original file line number Diff line number Diff line change
Expand Up @@ -138,7 +138,7 @@ x # type: ignore[name-defined, attr-defined] # E: Unused "type: ignore[attr-defi
[case testErrorCodeMissingWhenRequired]
# flags: --enable-error-code ignore-without-code
"x" # type: ignore # E: "type: ignore" comment without error code [ignore-without-code]
y # type: ignore # E: "type: ignore" comment without error code (hint: add [name-defined]) [ignore-without-code]
y # type: ignore # E: "type: ignore" comment without error code (currently ignored: [name-defined]) [ignore-without-code]
z # type: ignore[name-defined]
"a" # type: ignore[ignore-without-code]

Expand Down

0 comments on commit 6f39906

Please sign in to comment.