Skip to content

Commit 5b0cd60

Browse files
dnguy078claude
andcommitted
Fix dmypy traversal of missing graph dependencies
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 9105bb5 commit 5b0cd60

2 files changed

Lines changed: 40 additions & 2 deletions

File tree

mypy/dmypy_server.py

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -769,7 +769,7 @@ def find_reachable_changed_modules(
769769
state = graph[nxt.module]
770770
ancestors = state.ancestors or []
771771
for dep in state.dependencies + ancestors:
772-
if dep not in seen:
772+
if dep not in seen and dep in graph:
773773
seen.add(dep)
774774
worklist.append(BuildSource(graph[dep].path, graph[dep].id, followed=True))
775775
return changed, new_files
@@ -779,7 +779,11 @@ def direct_imports(
779779
) -> list[BuildSource]:
780780
"""Return the direct imports of module not included in seen."""
781781
state = graph[module[0]]
782-
return [BuildSource(graph[dep].path, dep, followed=True) for dep in state.dependencies]
782+
return [
783+
BuildSource(graph[dep].path, dep, followed=True)
784+
for dep in state.dependencies
785+
if dep in graph
786+
]
783787

784788
def find_added_suppressed(
785789
self, graph: mypy.build.Graph, seen: set[str], search_paths: SearchPaths

test-data/unit/daemon.test

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -802,3 +802,37 @@ Found 1 error in 1 file (checked 1 source file)
802802
[file test.py]
803803
from xml.etree.ElementTree import Element
804804
1 + 'a'
805+
806+
[case testDaemonRecheckMissingGraphDependency]
807+
$ dmypy start
808+
Daemon started
809+
$ dmypy check src/
810+
src/pkg/example.py:2: error: Name "x" already defined on line 1 [no-redef]
811+
Found 1 error in 1 file (checked 2 source files)
812+
== Return code: 1
813+
$ dmypy recheck
814+
src/pkg/example.py:2: error: Incompatible import of "x" (imported name has type "int", local name has type "str") [assignment]
815+
Found 1 error in 1 file (checked 53 source files)
816+
== Return code: 1
817+
$ dmypy recheck
818+
src/pkg/example.py:2: error: Incompatible import of "x" (imported name has type "int", local name has type "str") [assignment]
819+
Found 1 error in 1 file (checked 53 source files)
820+
== Return code: 1
821+
[file mypy.ini]
822+
\[mypy]
823+
follow_imports = normal
824+
mypy_path = src
825+
files = src/pkg/
826+
exclude = (?x)(
827+
\./.*
828+
| tests
829+
)
830+
\[mypy-pkg.tests.*]
831+
follow_imports = skip
832+
[file src/pkg/__init__.py]
833+
[file src/pkg/example.py]
834+
x = "1"
835+
from pkg.tests.test_something import x
836+
[file src/pkg/tests/__init__.py]
837+
[file src/pkg/tests/test_something.py]
838+
x = 1

0 commit comments

Comments
 (0)