diff --git a/mypy/build.py b/mypy/build.py index bf56075427d0..c3d36bc8755c 100644 --- a/mypy/build.py +++ b/mypy/build.py @@ -1551,6 +1551,10 @@ def exclude_from_backups(target_dir: str) -> None: def create_metastore(options: Options, parallel_worker: bool = False) -> MetadataStore: """Create the appropriate metadata store.""" + if not options.incremental: + # When incremental mode is disabled, use a no-op store to avoid + # creating a .mypy_cache directory. + return FilesystemMetadataStore(os.devnull) if options.sqlite_cache: # We use this flag in both coordinator and workers to seep up commits, # see mypy.metastore.connect_db() for details.