Skip to content

Fix staleness on changed follow imports options#20773

Merged
ilevkivskyi merged 2 commits into
python:masterfrom
ilevkivskyi:fix-follow-imports-changed
Feb 12, 2026
Merged

Fix staleness on changed follow imports options#20773
ilevkivskyi merged 2 commits into
python:masterfrom
ilevkivskyi:fix-follow-imports-changed

Conversation

@ilevkivskyi

Copy link
Copy Markdown
Member

This fixes the coarse grained part of #7777. I do not change semantics for daemon for two reasons:

  • Performance penalty from this fix will be minor for regular incremental, but may be well visible for the daemon.
  • And (more importantly) and just don't want to open this another can of worms (yet).

Some notes:

  • The general logic is straightforward, invalidate dependent modules, if import options for their dependencies changed.
  • It looks like the problem only affects suppressed dependencies, in all other situations we either already invalidate because something gets added to/removed from dependencies (e.g. when follow_imports = skip <-> normal), or there is no effect on the caller/importer (e.g. when follow_imports = normal <-> silent).
  • This requires another entry for CacheMeta but good new is I have an idea how to get rid of another entry I added in one of recent PRs. Essentially I will need to record early (import) errors anyway to send to parallel workers after we switch to parallel parsing, and if we do this we won't need the imports_ignored entry.

@ilevkivskyi ilevkivskyi requested a review from JukkaL February 9, 2026 14:46
@github-actions

This comment has been minimized.

@JukkaL

JukkaL commented Feb 11, 2026

Copy link
Copy Markdown
Collaborator

Not a full review, but I measured performance on a huge internal codebase, and I couldn't see any regression. So performance impact looks minimal.

@github-actions

Copy link
Copy Markdown
Contributor

According to mypy_primer, this change doesn't affect type check results on a corpus of open source code. ✅

@JukkaL JukkaL left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for fixing this old but quite annoying issue! The approach looks good.

@ilevkivskyi ilevkivskyi merged commit fe6fe1d into python:master Feb 12, 2026
23 checks passed
@ilevkivskyi ilevkivskyi deleted the fix-follow-imports-changed branch February 12, 2026 16:02
ilevkivskyi pushed a commit that referenced this pull request May 8, 2026
In mypy 1.19, re-running `mypy` with a saved cache and a file containing
an inline configuration comment (e.g. `# mypy:
disable-error-code="import-not-found"`) acted 'correctly', i.e. the same
behaviour on the first run vs subsequent runs.

In mypy 1.20 and newer, this is no longer the case. Running `mypy` with
a pre-existing cache fails to respect inline configuration comments for
stale modules, leading to confusing false-positive errors that can be
hard to debug.

This PR introduces a failing test as at current master, and then a fix
for the issue. I believe this is the right fix, though happy to change
as suggested by the maintainers, I'm not nearly as familiar with mypy
internals.

Notably also from L2376-80, it's by design that file-level comments
aren't cached:

```python
    # Note that the options we store in the cache are the options as
    # specified by the command line/config file and *don't* reflect
    # updates made by inline config directives in the file. This is
    # important, or otherwise the options would never match when
    # verifying the cache.
```

I believe that this regression was introduced in #20773

A

Co-authored-by: Adam Turner <turner@hudson-trading.com>
JukkaL pushed a commit that referenced this pull request May 10, 2026
In mypy 1.19, re-running `mypy` with a saved cache and a file containing
an inline configuration comment (e.g. `# mypy:
disable-error-code="import-not-found"`) acted 'correctly', i.e. the same
behaviour on the first run vs subsequent runs.

In mypy 1.20 and newer, this is no longer the case. Running `mypy` with
a pre-existing cache fails to respect inline configuration comments for
stale modules, leading to confusing false-positive errors that can be
hard to debug.

This PR introduces a failing test as at current master, and then a fix
for the issue. I believe this is the right fix, though happy to change
as suggested by the maintainers, I'm not nearly as familiar with mypy
internals.

Notably also from L2376-80, it's by design that file-level comments
aren't cached:

```python
    # Note that the options we store in the cache are the options as
    # specified by the command line/config file and *don't* reflect
    # updates made by inline config directives in the file. This is
    # important, or otherwise the options would never match when
    # verifying the cache.
```

I believe that this regression was introduced in #20773

A

Co-authored-by: Adam Turner <turner@hudson-trading.com>
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.

2 participants