Skip to content

Commit 579705d

Browse files
authored
Turn all warnings and bare notes into errors (#6650)
This means that all diagnostics are errors, which maybe have some notes "attached" to them. This makes sense, since all diagnostics cause an error exit code. Fixes #6574.
1 parent 6062421 commit 579705d

13 files changed

+46
-55
lines changed

mypy/build.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2180,7 +2180,7 @@ def generate_unused_ignore_notes(self) -> None:
21802180
# those errors to avoid spuriously flagging them as unused ignores.
21812181
if self.meta:
21822182
self.verify_dependencies(suppressed_only=True)
2183-
self.manager.errors.generate_unused_ignore_notes(self.xpath)
2183+
self.manager.errors.generate_unused_ignore_errors(self.xpath)
21842184

21852185

21862186
# Module import and diagnostic glue
@@ -2376,7 +2376,7 @@ def skipping_module(manager: BuildManager, line: int, caller_state: Optional[Sta
23762376
manager.errors.set_file(caller_state.xpath, caller_state.id)
23772377
manager.errors.report(line, 0,
23782378
"Import of '%s' ignored" % (id,),
2379-
severity='note')
2379+
severity='error')
23802380
manager.errors.report(line, 0,
23812381
"(Using --follow-imports=error, module not passed on command line)",
23822382
severity='note', only_once=True)
@@ -2392,7 +2392,7 @@ def skipping_ancestor(manager: BuildManager, id: str, path: str, ancestor_for: '
23922392
manager.errors.set_import_context([])
23932393
manager.errors.set_file(ancestor_for.xpath, ancestor_for.id)
23942394
manager.errors.report(-1, -1, "Ancestor package '%s' ignored" % (id,),
2395-
severity='note', only_once=True)
2395+
severity='error', only_once=True)
23962396
manager.errors.report(-1, -1,
23972397
"(Using --follow-imports=error, submodule passed on command line)",
23982398
severity='note', only_once=True)

mypy/checker.py

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -951,7 +951,7 @@ def check_func_def(self, defn: FuncItem, typ: CallableType, name: Optional[str])
951951
# entirely pass/Ellipsis.
952952
if isinstance(return_type, UninhabitedType):
953953
# This is a NoReturn function
954-
self.msg.note(message_registry.INVALID_IMPLICIT_RETURN, defn)
954+
self.msg.fail(message_registry.INVALID_IMPLICIT_RETURN, defn)
955955
else:
956956
self.msg.fail(message_registry.MISSING_RETURN_STATEMENT, defn)
957957

@@ -2793,7 +2793,7 @@ def visit_assert_stmt(self, s: AssertStmt) -> None:
27932793
self.expr_checker.accept(s.msg)
27942794

27952795
if isinstance(s.expr, TupleExpr) and len(s.expr.items) > 0:
2796-
self.warn(message_registry.MALFORMED_ASSERT, s)
2796+
self.fail(message_registry.MALFORMED_ASSERT, s)
27972797

27982798
# If this is asserting some isinstance check, bind that type in the following code
27992799
true_map, _ = self.find_isinstance_check(s.expr)
@@ -3747,10 +3747,6 @@ def fail(self, msg: str, context: Context) -> None:
37473747
"""Produce an error message."""
37483748
self.msg.fail(msg, context)
37493749

3750-
def warn(self, msg: str, context: Context) -> None:
3751-
"""Produce a warning message."""
3752-
self.msg.warn(msg, context)
3753-
37543750
def note(self, msg: str, context: Context, offset: int = 0) -> None:
37553751
"""Produce a note."""
37563752
self.msg.note(msg, context, offset=offset)

mypy/errors.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ class ErrorInfo:
4242
# The column number related to this error with file.
4343
column = 0 # -1 if unknown
4444

45-
# Either 'error', 'note', or 'warning'.
45+
# Either 'error' or 'note'
4646
severity = ''
4747

4848
# The error message.
@@ -242,7 +242,7 @@ def report(self,
242242
line: line number of error
243243
message: message to report
244244
blocker: if True, don't continue analysis after this error
245-
severity: 'error', 'note' or 'warning'
245+
severity: 'error' or 'note'
246246
file: if non-None, override current file as context
247247
only_once: if True, only report this exact message once per build
248248
origin_line: if non-None, override current context as origin
@@ -314,13 +314,13 @@ def clear_errors_in_targets(self, path: str, targets: Set[str]) -> None:
314314
self.only_once_messages.remove(info.message)
315315
self.error_info_map[path] = new_errors
316316

317-
def generate_unused_ignore_notes(self, file: str) -> None:
317+
def generate_unused_ignore_errors(self, file: str) -> None:
318318
ignored_lines = self.ignored_lines[file]
319319
if not self.is_typeshed_file(file) and file not in self.ignored_files:
320320
for line in ignored_lines - self.used_ignored_lines[file]:
321321
# Don't use report since add_error_info will ignore the error!
322322
info = ErrorInfo(self.import_context(), file, self.current_module(), None,
323-
None, line, -1, 'note', "unused 'type: ignore' comment",
323+
None, line, -1, 'error', "unused 'type: ignore' comment",
324324
False, False)
325325
self._add_error_info(file, info)
326326

mypy/messages.py

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -142,11 +142,6 @@ def note_multiline(self, messages: str, context: Context, file: Optional[str] =
142142
self.report(msg, context, 'note', file=file, origin=origin,
143143
offset=offset)
144144

145-
def warn(self, msg: str, context: Context, file: Optional[str] = None,
146-
origin: Optional[Context] = None) -> None:
147-
"""Report a warning message (unless disabled)."""
148-
self.report(msg, context, 'warning', file=file, origin=origin)
149-
150145
def quote_type_string(self, type_string: str) -> str:
151146
"""Quotes a type representation for use in messages."""
152147
no_quote_regex = r'^<(tuple|union): \d+ items>$'
@@ -1072,7 +1067,7 @@ def unsupported_type_type(self, item: Type, context: Context) -> None:
10721067
self.fail('Unsupported type Type[{}]'.format(self.format(item)), context)
10731068

10741069
def redundant_cast(self, typ: Type, context: Context) -> None:
1075-
self.note('Redundant cast to {}'.format(self.format(typ)), context)
1070+
self.fail('Redundant cast to {}'.format(self.format(typ)), context)
10761071

10771072
def unimported_type_becomes_any(self, prefix: str, typ: Type, ctx: Context) -> None:
10781073
self.fail("{} becomes {} due to an unfollowed import".format(prefix, self.format(typ)),
@@ -1163,7 +1158,7 @@ def disallowed_any_type(self, typ: Type, context: Context) -> None:
11631158
def incorrectly_returning_any(self, typ: Type, context: Context) -> None:
11641159
message = 'Returning Any from function declared to return {}'.format(
11651160
self.format(typ))
1166-
self.warn(message, context)
1161+
self.fail(message, context)
11671162

11681163
def untyped_decorated_function(self, typ: Type, context: Context) -> None:
11691164
if isinstance(typ, AnyType):

test-data/unit/check-38.test

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -56,24 +56,24 @@ def g(x: int): ...
5656

5757
[case testIgnoreScopeUnused1]
5858
# flags: --warn-unused-ignores
59-
( # type: ignore # N: unused 'type: ignore' comment
59+
( # type: ignore # E: unused 'type: ignore' comment
6060
"IGNORE" # type: ignore
61-
+ # type: ignore # N: unused 'type: ignore' comment
62-
0 # type: ignore # N: unused 'type: ignore' comment
63-
) # type: ignore # N: unused 'type: ignore' comment
61+
+ # type: ignore # E: unused 'type: ignore' comment
62+
0 # type: ignore # E: unused 'type: ignore' comment
63+
) # type: ignore # E: unused 'type: ignore' comment
6464

6565
[case testIgnoreScopeUnused2]
6666
# flags: --warn-unused-ignores
67-
( # type: ignore # N: unused 'type: ignore' comment
67+
( # type: ignore # E: unused 'type: ignore' comment
6868
"IGNORE"
6969
- # type: ignore
70-
0 # type: ignore # N: unused 'type: ignore' comment
71-
) # type: ignore # N: unused 'type: ignore' comment
70+
0 # type: ignore # E: unused 'type: ignore' comment
71+
) # type: ignore # E: unused 'type: ignore' comment
7272

7373
[case testIgnoreScopeUnused3]
7474
# flags: --warn-unused-ignores
75-
( # type: ignore # N: unused 'type: ignore' comment
75+
( # type: ignore # E: unused 'type: ignore' comment
7676
"IGNORE"
7777
/
7878
0 # type: ignore
79-
) # type: ignore # N: unused 'type: ignore' comment
79+
) # type: ignore # E: unused 'type: ignore' comment

test-data/unit/check-fastparse.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -319,10 +319,10 @@ def g(): # E: Type signature has too many arguments
319319
[case testFastParseMalformedAssert]
320320

321321
assert 1, 2
322-
assert (1, 2) # W: Assertion is always true, perhaps remove parentheses?
323-
assert (1, 2), 3 # W: Assertion is always true, perhaps remove parentheses?
322+
assert (1, 2) # E: Assertion is always true, perhaps remove parentheses?
323+
assert (1, 2), 3 # E: Assertion is always true, perhaps remove parentheses?
324324
assert ()
325-
assert (1,) # W: Assertion is always true, perhaps remove parentheses?
325+
assert (1,) # E: Assertion is always true, perhaps remove parentheses?
326326

327327
[case testFastParseAssertMessage]
328328

test-data/unit/check-flags.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ def f() -> NoReturn:
286286
# flags: --warn-no-return
287287
from mypy_extensions import NoReturn
288288

289-
def f() -> NoReturn: # N: Implicit return in function which does not return
289+
def f() -> NoReturn: # E: Implicit return in function which does not return
290290
non_trivial_function = 1
291291
[builtins fixtures/dict.pyi]
292292

@@ -432,7 +432,7 @@ x + ""
432432
[file mod.py]
433433
deliberate syntax error
434434
[out]
435-
main:2: note: Import of 'mod' ignored
435+
main:2: error: Import of 'mod' ignored
436436
main:2: note: (Using --follow-imports=error, module not passed on command line)
437437

438438
[case testIgnoreMissingImportsFalse]

test-data/unit/check-incremental.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1783,10 +1783,10 @@ import a
17831783
[file a.py.2]
17841784
//
17851785
[out1]
1786-
main:2: note: Import of 'a' ignored
1786+
main:2: error: Import of 'a' ignored
17871787
main:2: note: (Using --follow-imports=error, module not passed on command line)
17881788
[out2]
1789-
main:2: note: Import of 'a' ignored
1789+
main:2: error: Import of 'a' ignored
17901790
main:2: note: (Using --follow-imports=error, module not passed on command line)
17911791

17921792
[case testIncrementalFollowImportsVariable]

test-data/unit/check-modules.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -992,7 +992,7 @@ import mod
992992
[file mod.py]
993993
[builtins fixtures/module.pyi]
994994
[out]
995-
tmp/main.py:1: note: Import of 'mod' ignored
995+
tmp/main.py:1: error: Import of 'mod' ignored
996996
tmp/main.py:1: note: (Using --follow-imports=error, module not passed on command line)
997997

998998
[case testAncestorSuppressedWhileAlmostSilent]
@@ -1002,7 +1002,7 @@ tmp/main.py:1: note: (Using --follow-imports=error, module not passed on command
10021002
[file foo/__init__.py]
10031003
[builtins fixtures/module.pyi]
10041004
[out]
1005-
tmp/foo/bar.py: note: Ancestor package 'foo' ignored
1005+
tmp/foo/bar.py: error: Ancestor package 'foo' ignored
10061006
tmp/foo/bar.py: note: (Using --follow-imports=error, submodule passed on command line)
10071007

10081008
[case testStubImportNonStubWhileSilent]

test-data/unit/check-warnings.test

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ a = 1
1010
b = cast(str, a)
1111
c = cast(int, a)
1212
[out]
13-
main:5: note: Redundant cast to "int"
13+
main:5: error: Redundant cast to "int"
1414

1515
[case testRedundantCastWithIsinstance]
1616
# flags: --warn-redundant-casts
@@ -20,7 +20,7 @@ if isinstance(x, str):
2020
cast(str, x)
2121
[builtins fixtures/isinstance.pyi]
2222
[out]
23-
main:5: note: Redundant cast to "str"
23+
main:5: error: Redundant cast to "str"
2424

2525
[case testCastToSuperclassNotRedundant]
2626
# flags: --warn-redundant-casts
@@ -45,7 +45,7 @@ a = 1
4545
if int():
4646
a = 'a' # type: ignore
4747
if int():
48-
a = 2 # type: ignore # N: unused 'type: ignore' comment
48+
a = 2 # type: ignore # E: unused 'type: ignore' comment
4949
if int():
5050
a = 'b' # E: Incompatible types in assignment (expression has type "str", variable has type "int")
5151

@@ -57,8 +57,8 @@ from m import * # type: ignore
5757
[file m.py]
5858
pass
5959
[out]
60-
main:3: note: unused 'type: ignore' comment
61-
main:4: note: unused 'type: ignore' comment
60+
main:3: error: unused 'type: ignore' comment
61+
main:4: error: unused 'type: ignore' comment
6262

6363

6464
-- No return
@@ -144,7 +144,7 @@ from typing import Any
144144
def g() -> Any: pass
145145
def f() -> int: return g()
146146
[out]
147-
main:4: warning: Returning Any from function declared to return "int"
147+
main:4: error: Returning Any from function declared to return "int"
148148

149149
[case testReturnAnyForNotImplementedInBinaryMagicMethods]
150150
# flags: --warn-return-any
@@ -159,7 +159,7 @@ class A:
159159
def some(self) -> bool: return NotImplemented
160160
[builtins fixtures/notimplemented.pyi]
161161
[out]
162-
main:3: warning: Returning Any from function declared to return "bool"
162+
main:3: error: Returning Any from function declared to return "bool"
163163

164164
[case testReturnAnyFromTypedFunctionWithSpecificFormatting]
165165
# flags: --warn-return-any
@@ -174,7 +174,7 @@ typ = Tuple[int, int, int, int, int, int, int, int, int, int, int, int, int,
174174
def g() -> Any: pass
175175
def f() -> typ: return g()
176176
[out]
177-
main:11: warning: Returning Any from function declared to return <tuple: 91 items>
177+
main:11: error: Returning Any from function declared to return <tuple: 91 items>
178178

179179
[case testReturnAnySilencedFromTypedFunction]
180180
# flags: --warn-return-any

0 commit comments

Comments
 (0)