MCPcopy
hub / github.com/python/mypy / main

Function main

mypy/main.py:65–202  ·  view source on GitHub ↗

Main entry point to the type checker. Args: args: Custom command-line arguments. If not given, sys.argv[1:] will be used. clean_exit: Don't hard kill the process on exit. This allows catching SystemExit.

(
    *,
    args: list[str] | None = None,
    stdout: TextIO = sys.stdout,
    stderr: TextIO = sys.stderr,
    clean_exit: bool = False,
)

Source from the content-addressed store, hash-verified

63
64
65def main(
66 *,
67 args: list[str] | None = None,
68 stdout: TextIO = sys.stdout,
69 stderr: TextIO = sys.stderr,
70 clean_exit: bool = False,
71) -> None:
72 """Main entry point to the type checker.
73
74 Args:
75 args: Custom command-line arguments. If not given, sys.argv[1:] will
76 be used.
77 clean_exit: Don't hard kill the process on exit. This allows catching
78 SystemExit.
79 """
80 util.check_python_version("mypy")
81 t0 = time.time()
82 # To log stat() calls: os.stat = stat_proxy
83 sys.setrecursionlimit(RECURSION_LIMIT)
84 if args is None:
85 args = sys.argv[1:]
86
87 # Write an escape sequence instead of raising an exception on encoding errors.
88 if isinstance(stdout, TextIOWrapper) and stdout.errors == "strict":
89 stdout.reconfigure(errors="backslashreplace")
90
91 fscache = FileSystemCache()
92 sources, options = process_options(args, stdout=stdout, stderr=stderr, fscache=fscache)
93 if clean_exit:
94 options.fast_exit = False
95
96 formatter = util.FancyFormatter(
97 stdout, stderr, options.hide_error_codes, hide_success=bool(options.output)
98 )
99
100 if options.num_workers:
101 # Supporting both parsers would be really tricky, so just support the new one.
102 options.native_parser = True
103 if options.num_workers < 0:
104 fail("error: Number of workers cannot be negative", stderr, options)
105 if options.cache_dir == os.devnull:
106 fail("error: Cache must be enabled in parallel mode", stderr, options)
107 if not options.local_partial_types:
108 fail("error: --local-partial-types must be enabled in parallel mode", stderr, options)
109 if options.report_dirs:
110 fail(
111 "error: Reports are not supported in parallel mode yet\n"
112 "note: Use -n0 to disable parallel checking",
113 stderr,
114 options,
115 )
116
117 if options.allow_redefinition and not options.local_partial_types:
118 fail(
119 "error: --local-partial-types must be enabled if using --allow-redefinition",
120 stderr,
121 options,
122 )

Callers 1

console_entryFunction · 0.90

Calls 15

flushMethod · 0.95
format_errorMethod · 0.95
format_successMethod · 0.95
FileSystemCacheClass · 0.90
print_memory_profileFunction · 0.90
isinstanceFunction · 0.85
process_optionsFunction · 0.85
boolClass · 0.85
install_typesFunction · 0.85
run_buildFunction · 0.85
printFunction · 0.85

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…