python / python/mypy

Mypy does not recheck files when follow_imports changes for dependencies

Open
#7,777 3 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

bug priority-0-high topic-fine-grained-incremental
Dominant language
Python
Stars
20.6k
Forks
3.3k
PR merge metrics
PR metrics pending

Description

Steps to reproduce
  1. Create module test.py with import from nonexistent module:
from foo import bar
  1. Create mypy.ini file:
[mypy]

[mypy-foo]
ignore_missing_imports = True 
  1. Run mypy
$ mypy test.py 
Success: no issues found in 1 source file
  1. Comment out [mypy-foo] section in mypy.ini
[mypy]

# [mypy-foo]
# ignore_missing_imports = True 
  1. Run mypy
$ mypy test.py 
Success: no issues found in 1 source file
Expected result

After step 4, mypy should detect config change and (partially?) invalidate cache, leading to a type error.

$ mypy test.py 
test.py:1: error: Cannot find module named 'foo'
test.py:1: note: See https://mypy.readthedocs.io/en/latest/running_mypy.html#missing-imports
Found 1 error in 1 file (checked 1 source file)
Notes
  • Deleting .mypy_cache/ and re-running mypy fixes the issue.
  • Adding/removing ignore_missing_imports in the main [mypy] section does seem to invalidate the cache as expected. So this issue only seems to apply to [mypy-PATTERN] sections.
Versions
$ python --version
Python 3.7.3
$ mypy --version
mypy 0.740

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Reproduce the issue with test.py, mypy.ini, and the .mypy_cache/ directory using the configuration steps shown. Start by tracing cache invalidation for [mypy-PATTERN] sections and compare it with changes in the main [mypy] section. Done means changing the pattern section causes mypy to report the missing foo module without manually deleting the cache.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
devtools
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
48/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.