Skip to content

Don't create .mypy_cache directory when --no-incremental is used#20833

Open
Fridayai700 wants to merge 1 commit intopython:masterfrom
Fridayai700:fix-no-incremental-cache
Open

Don't create .mypy_cache directory when --no-incremental is used#20833
Fridayai700 wants to merge 1 commit intopython:masterfrom
Fridayai700:fix-no-incremental-cache

Conversation

@Fridayai700
Copy link

Summary

When running mypy with --no-incremental, the .mypy_cache directory is still created, even though the help text implies it won't be:

$ rm -rf .mypy_cache
$ mypy t.py --no-incremental
Success: no issues found in 1 source file
$ ls -d .mypy_cache
.mypy_cache  # Unexpected!

Root cause

The metadata store (which manages the cache directory) is initialized unconditionally in BuildManager.__init__(). While the cache_enabled flag prevents cache reads, the store still creates the cache directory on init (for SQLite stores) or on first write (for filesystem stores).

Fix

When options.incremental is False, create_metastore() now returns a no-op FilesystemMetadataStore backed by os.devnull. Both store implementations already handle os.devnull as a no-op — this is the same behavior users get with --cache-dir /dev/null, which was the documented workaround.

After:

$ rm -rf .mypy_cache
$ mypy t.py --no-incremental
Success: no issues found in 1 source file
$ ls -d .mypy_cache
ls: cannot access '.mypy_cache': No such file or directory  # Correct!

Test plan

  • Manual verification: --no-incremental no longer creates .mypy_cache
  • Normal mode still creates cache as expected
  • All 147 incremental-related tests pass
  • python -m pytest mypy/test/testcheck.py -k "testNoIncremental or testIncremental" -o "addopts=" — all pass

Fixes #19489

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 python#19489
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

--no-incremental still writes .mypy_cache

1 participant