From 08b106ec52f8b6d7c74b70c8838ffe953e76853d Mon Sep 17 00:00:00 2001 From: SynapShift <127070675+SynapShift@users.noreply.github.com> Date: Sun, 20 Sep 2026 14:07:19 +0800 Subject: [PATCH 1/2] Add dmypy namespace cache regression test --- test-data/unit/daemon.test | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test-data/unit/daemon.test b/test-data/unit/daemon.test index 448af5d080029..7f700b86db0a8 100644 --- a/test-data/unit/daemon.test +++ b/test-data/unit/daemon.test @@ -343,6 +343,32 @@ $ {python} -c "import sys; sys.stdout.write(open('log').read())" -- whether the source file got rehashed, which we don't want it to have been. $ {python} -c "x = open('.mypy_cache/3.11/bar.meta.ff', 'rb').read(); y = open('asdf.ff', 'rb').read(); assert x == y" +[case testDaemonFineGrainedCacheNamespacePackage] +$ mypy --cache-fine-grained --hide-error-codes src +src/pkg/nspkg/mod.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int") +Found 1 error in 1 file (checked 2 source files) +== Return code: 1 +$ dmypy run -- --use-fine-grained-cache +Daemon started +Success: no issues found in 2 source files +$ {python} -c "print('a: int = ' + repr('changed'))" >src/pkg/nspkg/mod.py +$ dmypy run -- --use-fine-grained-cache +src/pkg/nspkg/mod.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int") +Found 1 error in 1 file (checked 2 source files) +== Return code: 1 +$ dmypy run -- --use-fine-grained-cache +src/pkg/nspkg/mod.py:1: error: Incompatible types in assignment (expression has type "str", variable has type "int") +Found 1 error in 1 file (checked 2 source files) +== Return code: 1 +$ dmypy stop +Daemon stopped +[file src/pkg/__init__.py] +[file src/pkg/nspkg/mod.py] +a: int = "" +[file mypy.ini] +\[mypy] +files = src/ + [case testDaemonSuggest] $ dmypy start --log-file log.txt -- --follow-imports=error --no-error-summary Daemon started From 4e837995df3bacd881da7963498d1f299fe14b6d Mon Sep 17 00:00:00 2001 From: SynapShift <127070675+SynapShift@users.noreply.github.com> Date: Sun, 20 Sep 2026 14:07:32 +0800 Subject: [PATCH 2/2] Fix dmypy namespace package cache traversal --- mypy/dmypy_server.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/mypy/dmypy_server.py b/mypy/dmypy_server.py index 066fbf9bed2d6..a7a1f43f10f51 100644 --- a/mypy/dmypy_server.py +++ b/mypy/dmypy_server.py @@ -769,7 +769,8 @@ def find_reachable_changed_modules( state = graph[nxt.module] ancestors = state.ancestors or [] for dep in state.dependencies + ancestors: - if dep not in seen: + # Namespace package ancestors don't always have a graph node. + if dep not in seen and dep in graph: seen.add(dep) worklist.append(BuildSource(graph[dep].path, graph[dep].id, followed=True)) return changed, new_files