-
-
Notifications
You must be signed in to change notification settings - Fork 3.2k
Expand file tree
/
Copy path__main__.py
More file actions
50 lines (42 loc) · 1.49 KB
/
__main__.py
File metadata and controls
50 lines (42 loc) · 1.49 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
"""Mypy type checker command line tool."""
from __future__ import annotations
import os
import sys
import traceback
from mypy.main import main, process_options
from mypy.util import FancyFormatter
def console_entry() -> None:
try:
main()
sys.stdout.flush()
sys.stderr.flush()
except BrokenPipeError:
# Python flushes standard streams on exit; redirect remaining output
# to devnull to avoid another BrokenPipeError at shutdown
devnull = os.open(os.devnull, os.O_WRONLY)
os.dup2(devnull, sys.stdout.fileno())
sys.exit(2)
except KeyboardInterrupt:
_, options = process_options(args=sys.argv[1:])
if options.show_traceback:
sys.stdout.write(traceback.format_exc())
formatter = FancyFormatter(sys.stdout, sys.stderr, False)
msg = "Interrupted\n"
sys.stdout.write(formatter.style(msg, color="red", bold=True))
sys.stdout.flush()
sys.stderr.flush()
sys.exit(2)
except Exception as e:
# Try reporting any uncaught error canonically, otherwise just flush the traceback.
try:
import mypy.errors
_, options = process_options(args=sys.argv[1:])
mypy.errors.report_internal_error(e, None, 0, None, options)
except Exception:
pass
sys.stdout.write(traceback.format_exc())
sys.stdout.flush()
sys.stderr.flush()
sys.exit(2)
if __name__ == "__main__":
console_entry()