Skip to content

Commit 6a8d68c

Browse files
committed
Turn all warnings and bare notes into errors
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 ffb3ce9 commit 6a8d68c

13 files changed

+35
-45
lines changed

mypy/build.py

+3-3
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

+2-6
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/checkmember.py

-1
Original file line numberDiff line numberDiff line change
@@ -328,7 +328,6 @@ def analyze_member_var_access(name: str,
328328
# independently of types.
329329
if mx.is_lvalue and not mx.chk.get_final_context():
330330
check_final_member(name, info, mx.msg, mx.context)
331-
332331
return analyze_var(name, v, itype, info, mx, implicit=implicit)
333332
elif isinstance(v, FuncDef):
334333
assert False, "Did not expect a function"

mypy/errors.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -299,13 +299,13 @@ def clear_errors_in_targets(self, path: str, targets: Set[str]) -> None:
299299
self.only_once_messages.remove(info.message)
300300
self.error_info_map[path] = new_errors
301301

302-
def generate_unused_ignore_notes(self, file: str) -> None:
302+
def generate_unused_ignore_errors(self, file: str) -> None:
303303
ignored_lines = self.ignored_lines[file]
304304
if not self.is_typeshed_file(file) and file not in self.ignored_files:
305305
for line in ignored_lines - self.used_ignored_lines[file]:
306306
# Don't use report since add_error_info will ignore the error!
307307
info = ErrorInfo(self.import_context(), file, self.current_module(), None,
308-
None, line, -1, 'note', "unused 'type: ignore' comment",
308+
None, line, -1, 'error', "unused 'type: ignore' comment",
309309
False, False)
310310
self._add_error_info(file, info)
311311

mypy/messages.py

+2-7
Original file line numberDiff line numberDiff line change
@@ -135,11 +135,6 @@ def note_multiline(self, messages: str, context: Context, file: Optional[str] =
135135
self.report(msg, context, 'note', file=file, origin=origin,
136136
offset=offset)
137137

138-
def warn(self, msg: str, context: Context, file: Optional[str] = None,
139-
origin: Optional[Context] = None) -> None:
140-
"""Report a warning message (unless disabled)."""
141-
self.report(msg, context, 'warning', file=file, origin=origin)
142-
143138
def quote_type_string(self, type_string: str) -> str:
144139
"""Quotes a type representation for use in messages."""
145140
no_quote_regex = r'^<(tuple|union): \d+ items>$'
@@ -1065,7 +1060,7 @@ def unsupported_type_type(self, item: Type, context: Context) -> None:
10651060
self.fail('Unsupported type Type[{}]'.format(self.format(item)), context)
10661061

10671062
def redundant_cast(self, typ: Type, context: Context) -> None:
1068-
self.note('Redundant cast to {}'.format(self.format(typ)), context)
1063+
self.fail('Redundant cast to {}'.format(self.format(typ)), context)
10691064

10701065
def unimported_type_becomes_any(self, prefix: str, typ: Type, ctx: Context) -> None:
10711066
self.fail("{} becomes {} due to an unfollowed import".format(prefix, self.format(typ)),
@@ -1156,7 +1151,7 @@ def disallowed_any_type(self, typ: Type, context: Context) -> None:
11561151
def incorrectly_returning_any(self, typ: Type, context: Context) -> None:
11571152
message = 'Returning Any from function declared to return {}'.format(
11581153
self.format(typ))
1159-
self.warn(message, context)
1154+
self.fail(message, context)
11601155

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

test-data/unit/check-fastparse.test

+3-3
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

+2-2
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

+2-2
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

+2-2
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

+8-8
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

test-data/unit/cmdline.test

+3-3
Original file line numberDiff line numberDiff line change
@@ -385,7 +385,7 @@ follow_imports = error
385385
[file a.py]
386386
/ # No error reported
387387
[out]
388-
main.py:1: note: Import of 'a' ignored
388+
main.py:1: error: Import of 'a' ignored
389389
main.py:1: note: (Using --follow-imports=error, module not passed on command line)
390390
main.py:2: error: Revealed type is 'Any'
391391
main.py:4: error: Revealed type is 'Any'
@@ -423,7 +423,7 @@ bla bla
423423
bla bla
424424
[out]
425425
normal.py:2: error: Unsupported operand types for + ("int" and "str")
426-
main.py:4: note: Import of 'error' ignored
426+
main.py:4: error: Import of 'error' ignored
427427
main.py:4: note: (Using --follow-imports=error, module not passed on command line)
428428
main.py:5: error: Revealed type is 'builtins.int'
429429
main.py:6: error: Revealed type is 'builtins.int'
@@ -1114,7 +1114,7 @@ follow_imports_for_stubs = True
11141114
import math
11151115
math.frobnicate()
11161116
[out]
1117-
main.py:1: note: Import of 'math' ignored
1117+
main.py:1: error: Import of 'math' ignored
11181118
main.py:1: note: (Using --follow-imports=error, module not passed on command line)
11191119

11201120
[case testFollowImportStubs2]

test-data/unit/daemon.test

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ Daemon started
110110
$ dmypy check foo.py bar.py
111111
$ dmypy recheck
112112
$ dmypy recheck --update foo.py --remove bar.py sir_not_appearing_in_this_film.py
113-
foo.py:1: note: Import of 'bar' ignored
113+
foo.py:1: error: Import of 'bar' ignored
114114
foo.py:1: note: (Using --follow-imports=error, module not passed on command line)
115115
== Return code: 1
116116
$ dmypy recheck --update bar.py

test-data/unit/fine-grained-modules.test

+5-5
Original file line numberDiff line numberDiff line change
@@ -1822,10 +1822,10 @@ x = 1
18221822
[file c.py.2]
18231823
x = '2'
18241824
[out]
1825-
a.py:2: note: Import of 'b' ignored
1825+
a.py:2: error: Import of 'b' ignored
18261826
a.py:2: note: (Using --follow-imports=error, module not passed on command line)
18271827
==
1828-
a.py:2: note: Import of 'b' ignored
1828+
a.py:2: error: Import of 'b' ignored
18291829
a.py:2: note: (Using --follow-imports=error, module not passed on command line)
18301830

18311831
[case testErrorButDontIgnore2]
@@ -1842,7 +1842,7 @@ x = 1
18421842
x = '2'
18431843
[out]
18441844
==
1845-
a.py:2: note: Import of 'b' ignored
1845+
a.py:2: error: Import of 'b' ignored
18461846
a.py:2: note: (Using --follow-imports=error, module not passed on command line)
18471847

18481848
-- TODO: This test fails because p.b does not depend on p (#4847)
@@ -1862,7 +1862,7 @@ x = 1
18621862
x = '2'
18631863
[out]
18641864
==
1865-
p/b.py: note: Ancestor package 'p' ignored
1865+
p/b.py: error: Ancestor package 'p' ignored
18661866
p/b.py: note: (Using --follow-imports=error, submodule passed on command line)
18671867

18681868
[case testErrorButDontIgnore4]
@@ -1880,7 +1880,7 @@ x = 1
18801880
[delete z.py.2]
18811881
[out]
18821882
==
1883-
p/b.py: note: Ancestor package 'p' ignored
1883+
p/b.py: error: Ancestor package 'p' ignored
18841884
p/b.py: note: (Using --follow-imports=error, submodule passed on command line)
18851885
p/b.py:1: error: Cannot find module named 'z'
18861886
p/b.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports

0 commit comments

Comments
 (0)