Skip to content

Commit f5a3405

Browse files
committed
Improve error reporting when --install-types has no cache (#10667)
There are no tests since our test framework makes it tricky to write tests for these kinds of scenarios. Tested manually. Work on #10600.
1 parent 0b65866 commit f5a3405

File tree

1 file changed

+13
-2
lines changed

1 file changed

+13
-2
lines changed

mypy/main.py

+13-2
Original file line numberDiff line numberDiff line change
@@ -77,6 +77,10 @@ def main(script_path: Optional[str],
7777
if options.non_interactive and not options.install_types:
7878
fail("Error: --non-interactive is only supported with --install-types", stderr, options)
7979

80+
if options.install_types and not options.incremental:
81+
fail("Error: --install-types not supported with incremental mode disabled",
82+
stderr, options)
83+
8084
if options.install_types and not sources:
8185
install_types(options.cache_dir, formatter, non_interactive=options.non_interactive)
8286
return
@@ -1090,8 +1094,15 @@ def install_types(cache_dir: str,
10901094
non_interactive: bool = False) -> None:
10911095
"""Install stub packages using pip if some missing stubs were detected."""
10921096
if not os.path.isdir(cache_dir):
1093-
sys.stderr.write(
1094-
"Error: no mypy cache directory (you must enable incremental mode)\n")
1097+
if not after_run:
1098+
sys.stderr.write(
1099+
"Error: Can't determine which types to install with no files to check " +
1100+
"(and no cache from previous mypy run)\n"
1101+
)
1102+
else:
1103+
sys.stderr.write(
1104+
"Error: --install-types failed (no mypy cache directory)\n"
1105+
)
10951106
sys.exit(2)
10961107
fnam = build.missing_stubs_file(cache_dir)
10971108
if not os.path.isfile(fnam):

0 commit comments

Comments
 (0)