From b33d45ed35968899d48db18814232f0e747dde4c Mon Sep 17 00:00:00 2001 From: Ivan Levkivskyi Date: Thu, 20 Nov 2025 11:27:12 +0000 Subject: [PATCH] Update import map when new modules added --- mypy/server/update.py | 2 ++ test-data/unit/fine-grained-modules.test | 16 ++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/mypy/server/update.py b/mypy/server/update.py index 839090ca45ac..86ccb57c2a3f 100644 --- a/mypy/server/update.py +++ b/mypy/server/update.py @@ -631,6 +631,8 @@ def restore(ids: list[str]) -> None: # Find any other modules brought in by imports. changed_modules = [(st.id, st.xpath) for st in new_modules] + for m in new_modules: + manager.import_map[m.id] = set(m.dependencies + m.suppressed) # If there are multiple modules to process, only process one of them and return # the remaining ones to the caller. diff --git a/test-data/unit/fine-grained-modules.test b/test-data/unit/fine-grained-modules.test index f28dbaa1113b..3ee07a03792f 100644 --- a/test-data/unit/fine-grained-modules.test +++ b/test-data/unit/fine-grained-modules.test @@ -2244,3 +2244,19 @@ undefined a.py:1: error: Cannot find implementation or library stub for module named "foobar" a.py:1: note: See https://mypy.readthedocs.io/en/stable/running_mypy.html#missing-imports == + +[case testDaemonImportMapRefresh] +# cmd: mypy main.py +[file main.py] +[file main.py.2] +import a.b +reveal_type(a.b.foo()) +[file a/__init__.pyi] +[file a/b.pyi] +import a.c +def foo() -> a.c.C: ... +[file a/c.pyi] +class C: ... +[out] +== +main.py:2: note: Revealed type is "a.c.C"