8000 Exit with code 2 on blocking errors · python/mypy@beb6bac · GitHub
[go: up one dir, main page]

Skip to content

Commit beb6bac

Browse files
committed
Exit with code 2 on blocking errors
Exit with code 2 on blocking errors, while continuing to exit with 1 when there are nonblocking errors. Add test infrastructure. Fixes #2754.
1 parent 92dfc2d commit beb6bac

File tree

4 files changed

+104
-2
lines changed

4 files changed

+104
-2
lines changed

mypy/main.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,12 +72,14 @@ def flush_errors(a: List[str], serious: bool) -> None:
7272
f.write(m + '\n')
7373
f.flush()
7474
except BrokenPipeError:
75-
sys.exit(1)
75+
sys.exit(2)
7676

7777
serious = False
78+
blockers = False
7879
try:
7980
type_check_only(sources, bin_dir, options, flush_errors)
8081
except CompileError as e:
82+
blockers = True
8183
if not e.use_stdout:
8284
serious = True
8385
if options.warn_unused_configs and options.unused_configs:
@@ -89,7 +91,8 @@ def flush_errors(a: List[str], serious: bool) -> None:
8991
t1 = time.time()
9092
util.write_junit_xml(t1 - t0, serious, messages, options.junit_xml)
9193
if messages:
92-
sys.exit(1)
94+
code = 2 if blockers else 1
95+
sys.exit(code)
9396

9497

9598
def find_bin_directory(script_path: str) -> str:

mypy/test/testcmdline.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
5858
outb = process.stdout.read()
5959
# Split output into lines.
6060
out = [s.rstrip('\n\r') for s in str(outb, 'utf8').splitlines()]
61+
result = process.wait()
6162
# Remove temp file.
6263
os.remove(program_path)
6364
# Compare actual output to expected.
@@ -78,6 +79,7 @@ def test_python_cmdline(testcase: DataDrivenTestCase) -> None:
7879
path))
7980
else:
8081
out = normalize_error_messages(out)
82+
out.append('== Return code: {}'.format(result))
8183
assert_string_arrays_equal(testcase.output, out,
8284
'Invalid output ({}, line {})'.format(
8385
testcase.file, testcase.line))

0 commit comments

Comments
 (0)
0