Remove cache files created for namespace packages#180
Merged
sobolevn merged 4 commits intotypeddjango:masterfrom Jan 16, 2026
Merged
Remove cache files created for namespace packages#180sobolevn merged 4 commits intotypeddjango:masterfrom
sobolevn merged 4 commits intotypeddjango:masterfrom
Conversation
bzoracler
commented
Jan 16, 2026
| cache_file /= ".".join([str(part) for part in sys.version_info[:2]]) | ||
| for part in fpath_no_suffix.parts: | ||
| for i, part in enumerate(fpath_no_suffix.parts): | ||
| if (i == 0) and part.endswith("-stubs") and ((cache_file / part.removesuffix("-stubs")).is_dir()): |
Contributor
Author
There was a problem hiding this comment.
This guards against removal of unrelated cache files.
For example, if we used pytest-mypy-plugins to type-check a file called abc-stubs.pyi, it should not remove the cache files abc.data.json and abc.meta.json.
I didn't add tests for this; testing this requires getting pytest-mypy-plugins to type-check a module that's not called main.py, or to arbitrarily check an entire package, and I don't think we can do that?
sobolevn
approved these changes
Jan 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR fixes an issue where cache files created from namespace packages are not cleaned up.
For the following concrete example,
during pytest, mypy creates the following under
/tmp/.mypy_cache/3.1x/:pkg/__init__.{data & meta}.jsonpkg/module.{data & meta}.jsonnspkg/module.{data & meta}.jsonnspkg.{data & meta}.jsonThe existing implementation of
YamlTestItem.remove_cache_filesonly passespathlib.Patharguments pointing to files, not directories, so while mypy creates.{data,meta}.jsoncache files for namespace packages' directory names,.remove_cache_files()never removes these cache files.