Skip to content

fix dmypy namespace cache 20519 - #22009

Open
SynapShift wants to merge 2 commits into
python:masterfrom
SynapShift:codex/fix-dmypy-namespace-cache-20519
Open

SynapShift wants to merge 2 commits into
python:masterfrom
SynapShift:codex/fix-dmypy-namespace-cache-20519

Conversation

@SynapShift

Copy link
Copy Markdown

Summary

When dmypy reuses a fine-grained cache, a namespace-package ancestor can appear in State.ancestors without having a corresponding graph node. On a later unchanged run, find_reachable_changed_modules() indexed that missing node and crashed with KeyError.

Only enqueue dependencies and ancestors that are present in the graph. Add an end-to-end daemon regression test covering the original sequence: create a fine-grained cache containing an error, start dmypy from that cache, change a module below a namespace package, and run the daemon again without further changes.

Fixes #20519.

Tests

  • python -m pytest -o addopts='' -q "mypy/test/testdaemon.py::DaemonSuite::daemon.test::testDaemonFineGrainedCacheNamespacePackage"
  • python -m pytest -o addopts='' -q mypy/test/testfinegrainedcache.py — 538 passed, 227 skipped
  • python -m ruff check mypy/dmypy_server.py
  • python -m ruff format --check mypy/dmypy_server.py

@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. ✅

@SynapShift SynapShift changed the title Codex/fix dmypy namespace cache 20519 fix dmypy namespace cache 20519 Sep 20, 2026
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.

dmypy's --use-fine-grained-cache crashes with KeyError on namespace packages

1 participant