From 5a99b4096033c1c5db389bc31a67fde77572ca70 Mon Sep 17 00:00:00 2001 From: Friday Date: Tue, 17 Feb 2026 13:24:32 +0000 Subject: [PATCH] Don't create .mypy_cache directory when --no-incremental is used When running mypy with --no-incremental, the .mypy_cache directory was still being created. This happened because the metadata store was initialized unconditionally, and the filesystem/sqlite stores create the cache directory during initialization or on first write. The fix creates a no-op FilesystemMetadataStore backed by os.devnull when incremental mode is disabled, which prevents any cache directory creation or file writes. Both FilesystemMetadataStore and SqliteMetadataStore already handle os.devnull as a no-op case, so this approach is consistent with the existing --cache-dir=/dev/null behavior. Fixes #19489 --- mypy/build.py | 4 ++++ 1 file changed, 4 insertions(+) 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.