Skip to content

Traverse module ancestors when traversing reachable graph nodes during dmypy update #18906

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 11 additions & 3 deletions mypy/dmypy_server.py
Original file line number Diff line number Diff line change
Expand Up @@ -620,6 +620,9 @@ def fine_grained_increment_follow_imports(
t1 = time.time()
manager.log(f"fine-grained increment: find_changed: {t1 - t0:.3f}s")

# Track all modules encountered so far. New entries for all dependencies
# are added below by other module finding methods below. All dependencies
# in graph but not in `seen` are considered deleted at the end of this method.
seen = {source.module for source in sources}

# Find changed modules reachable from roots (or in roots) already in graph.
Expand Down Expand Up @@ -736,7 +739,9 @@ def find_reachable_changed_modules(
Args:
roots: modules where to start search from
graph: module graph to use for the search
seen: modules we've seen before that won't be visited (mutated here!!)
seen: modules we've seen before that won't be visited (mutated here!!).
Needed to accumulate all modules encountered during update and remove
everything that no longer exists.
changed_paths: which paths have changed (stop search here and return any found)
Return (encountered reachable changed modules,
Expand All @@ -756,7 +761,8 @@ def find_reachable_changed_modules(
changed.append((nxt.module, nxt.path))
elif nxt.module in graph:
state = graph[nxt.module]
for dep in state.dependencies:
ancestors = state.ancestors or []
for dep in state.dependencies + ancestors:
if dep not in seen:
seen.add(dep)
worklist.append(BuildSource(graph[dep].path, graph[dep].id, followed=True))
Expand All @@ -775,7 +781,9 @@ def find_added_suppressed(
"""Find suppressed modules that have been added (and not included in seen).
Args:
seen: reachable modules we've seen before (mutated here!!)
seen: reachable modules we've seen before (mutated here!!).
Needed to accumulate all modules encountered during update and remove
everything that no longer exists.
Return suppressed, added modules.
"""
Expand Down
18 changes: 18 additions & 0 deletions test-data/unit/daemon.test
Original file line number Diff line number Diff line change
Expand Up @@ -647,3 +647,21 @@ b: str
from demo.test import a
[file demo/test.py]
a: int

[case testDaemonImportAncestors]
$ dmypy run test.py
Daemon started
test.py:2: error: Unsupported operand types for + ("int" and "str") [operator]
Found 1 error in 1 file (checked 1 source file)
== Return code: 1
$ dmypy run test.py
test.py:2: error: Unsupported operand types for + ("int" and "str") [operator]
Found 1 error in 1 file (checked 1 source file)
== Return code: 1
$ dmypy run test.py
test.py:2: error: Unsupported operand types for + ("int" and "str") [operator]
Found 1 error in 1 file (checked 1 source file)
== Return code: 1
[file test.py]
from xml.etree.ElementTree import Element
1 + 'a'