Skip to content

Commit

Permalink
Improve error reporting when --install-types has no cache (#10667)
Browse files Browse the repository at this point in the history
There are no tests since our test framework makes it tricky to
write tests for these kinds of scenarios. Tested manually.

Work on #10600.
  • Loading branch information
JukkaL committed Jun 18, 2021
1 parent b0e36aa commit bf231be
Showing 1 changed file with 13 additions and 2 deletions.
15 changes: 13 additions & 2 deletions mypy/main.py
Expand Up @@ -77,6 +77,10 @@ def main(script_path: Optional[str],
if options.non_interactive and not options.install_types:
fail("Error: --non-interactive is only supported with --install-types", stderr, options)

if options.install_types and not options.incremental:
fail("Error: --install-types not supported with incremental mode disabled",
stderr, options)

if options.install_types and not sources:
install_types(options.cache_dir, formatter, non_interactive=options.non_interactive)
return
Expand Down Expand Up @@ -1090,8 +1094,15 @@ def install_types(cache_dir: str,
non_interactive: bool = False) -> None:
"""Install stub packages using pip if some missing stubs were detected."""
if not os.path.isdir(cache_dir):
sys.stderr.write(
"Error: no mypy cache directory (you must enable incremental mode)\n")
if not after_run:
sys.stderr.write(
"Error: Can't determine which types to install with no files to check " +
"(and no cache from previous mypy run)\n"
)
else:
sys.stderr.write(
"Error: --install-types failed (no mypy cache directory)\n"
)
sys.exit(2)
fnam = build.missing_stubs_file(cache_dir)
if not os.path.isfile(fnam):
Expand Down

0 comments on commit bf231be

Please sign in to comment.