You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
False positives about non-existing import when using mypy cache #20300
I'm getting a bunch of false positives when reusing .mypy_cache in CI and refactoring the code base. They disappear after clearing the CI mypy cache, so they must be related to the cache.
To Reproduce
I'm not sure about the exact steps. This is what I've gathered so far:
Run mypy on an existing project
Rename some module
Re-run mypy
I was able to reproduce the "reverse" of the original issue locally in the repo (closed source) by running mypy in a branch containing a refactor, switching back to the default branch, and re-running mypy. I then got the same type of errors, but complaining that the modules in the refactor branch could not be found.
Only the first run of mypy fails. Subsequent runs "understand" that some code has been renamed, and no longer produces any errors.
Expected Behavior
The code should pass validation on the first try without having to clear the cache.
Actual Behavior
some/path/__init__.py:1: error:
Cannot find implementation or library stub for module named
"project.module.submodule" [import-not-found]
from collections import defaultdict
^
Clearly the built-in collections module import doesn't depend on a project-internal module, so this error message is nonsensical.
Your Environment
Mypy version used: 1.15.0
Mypy command-line flags: None
Mypy configuration options from mypy.ini (and other config files): pyproject.toml.txt
Could you upgrade to latest mypy==1.18.2 (or, ideally, install from master with pip install git+https://github.com/python/mypy - this installs a slow, non-compiled version, but contains all latest changes) and retry your experiment, please?
This could be fixed by #19044, but that's not very likely unless your repository contains some namespace packages (those without __init__.py). However, there have been other cache/incremental updates since 1.15.0, so your issue might be fixed already!
Activity
VictorEngmarkHexagon commentedon Nov 26, 2025
@sterliakov Does this sound like something fixed by #19044?
sterliakov commentedon Nov 26, 2025
Could you upgrade to latest
mypy==1.18.2(or, ideally, install from master withpip install git+https://github.com/python/mypy- this installs a slow, non-compiled version, but contains all latest changes) and retry your experiment, please?This could be fixed by #19044, but that's not very likely unless your repository contains some namespace packages (those without
__init__.py). However, there have been other cache/incremental updates since 1.15.0, so your issue might be fixed already!VictorEngmarkHexagon commentedon Nov 26, 2025
I don't have time to do the update at the moment, so I've disabled caching for now. Will get back to this ticket later.
VictorEngmarkHexagon commentedon Dec 16, 2025
Thank you @sterliakov, upgrading to 1.17.1 fixed it!