Skip to content

Commit 201d116

Browse files
authored
Return 0 if there are only notes and no errors (#13879)
Fixes #10013 See #13851 (comment) for motivation, also this sounds generally reasonable.
1 parent b3d94dc commit 201d116

File tree

3 files changed

+34
-13
lines changed

3 files changed

+34
-13
lines changed

mypy/main.py

+2-2
Original file line numberDiff line numberDiff line change
@@ -110,10 +110,10 @@ def main(
110110
print_memory_profile()
111111

112112
code = 0
113-
if messages:
113+
n_errors, n_notes, n_files = util.count_stats(messages)
114+
if messages and n_notes < len(messages):
114115
code = 2 if blockers else 1
115116
if options.error_summary:
116-
n_errors, n_notes, n_files = util.count_stats(messages)
117117
if n_errors:
118118
summary = formatter.format_error(
119119
n_errors, n_files, len(sources), blockers=blockers, use_color=options.color_output

mypy/test/testpythoneval.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ def test_python_evaluation(testcase: DataDrivenTestCase, cache_dir: str) -> None
8181
# Normalize paths so that the output is the same on Windows and Linux/macOS.
8282
line = line.replace(test_temp_dir + os.sep, test_temp_dir + "/")
8383
output.append(line.rstrip("\r\n"))
84-
if returncode == 0:
84+
if returncode == 0 and not output:
8585
# Execute the program.
8686
proc = subprocess.run(
8787
[interpreter, "-Wignore", program], cwd=test_temp_dir, capture_output=True

test-data/unit/cmdline.test

+31-10
Original file line numberDiff line numberDiff line change
@@ -425,6 +425,7 @@ follow_imports = skip
425425
[out]
426426
main.py:2: note: Revealed type is "Any"
427427
main.py:4: note: Revealed type is "Any"
428+
== Return code: 0
428429

429430
[case testConfigFollowImportsError]
430431
# cmd: mypy main.py
@@ -517,7 +518,7 @@ reveal_type(missing.x) # Expect Any
517518
ignore_missing_imports = True
518519
[out]
519520
main.py:2: note: Revealed type is "Any"
520-
521+
== Return code: 0
521522

522523
[case testFailedImportOnWrongCWD]
523524
# cmd: mypy main.py
@@ -654,15 +655,26 @@ python_version = 3.6
654655
[file int_pow.py]
655656
a = 1
656657
b = a + 2
657-
reveal_type(a**0) # N: Revealed type is "Literal[1]"
658-
reveal_type(a**1) # N: Revealed type is "builtins.int"
659-
reveal_type(a**2) # N: Revealed type is "builtins.int"
660-
reveal_type(a**-0) # N: Revealed type is "Literal[1]"
661-
reveal_type(a**-1) # N: Revealed type is "builtins.float"
662-
reveal_type(a**(-2)) # N: Revealed type is "builtins.float"
663-
reveal_type(a**b) # N: Revealed type is "Any"
664-
reveal_type(a.__pow__(2)) # N: Revealed type is "builtins.int"
665-
reveal_type(a.__pow__(a)) # N: Revealed type is "Any"
658+
reveal_type(a**0)
659+
reveal_type(a**1)
660+
reveal_type(a**2)
661+
reveal_type(a**-0)
662+
reveal_type(a**-1)
663+
reveal_type(a**(-2))
664+
reveal_type(a**b)
665+
reveal_type(a.__pow__(2))
666+
reveal_type(a.__pow__(a))
667+
[out]
668+
int_pow.py:3: note: Revealed type is "Literal[1]"
669+
int_pow.py:4: note: Revealed type is "builtins.int"
670+
int_pow.py:5: note: Revealed type is "builtins.int"
671+
int_pow.py:6: note: Revealed type is "Literal[1]"
672+
int_pow.py:7: note: Revealed type is "builtins.float"
673+
int_pow.py:8: note: Revealed type is "builtins.float"
674+
int_pow.py:9: note: Revealed type is "Any"
675+
int_pow.py:10: note: Revealed type is "builtins.int"
676+
int_pow.py:11: note: Revealed type is "Any"
677+
== Return code: 0
666678

667679
[case testDisallowAnyGenericsBuiltinCollections]
668680
# cmd: mypy m.py
@@ -1484,3 +1496,12 @@ pass
14841496
[out]
14851497
Warning: --enable-recursive-aliases is deprecated; recursive types are enabled by default
14861498
== Return code: 0
1499+
1500+
[case testNotesOnlyResultInExitSuccess]
1501+
# cmd: mypy a.py
1502+
[file a.py]
1503+
def f():
1504+
x: int = "no"
1505+
[out]
1506+
a.py:2: note: By default the bodies of untyped functions are not checked, consider using --check-untyped-defs
1507+
== Return code: 0

0 commit comments

Comments
 (0)