diff --git a/mypy/server/aststrip.py b/mypy/server/aststrip.py index c2fbd3ce9544..be466e0beec5 100644 --- a/mypy/server/aststrip.py +++ b/mypy/server/aststrip.py @@ -229,7 +229,8 @@ def visit_import_all(self, node: ImportAll) -> None: # (The description in visit_import is relevant here as well.) if self.names: for name in node.imported_names: - del self.names[name] + if name in self.names: + del self.names[name] node.imported_names = [] def visit_for_stmt(self, node: ForStmt) -> None: diff --git a/test-data/unit/fine-grained-modules.test b/test-data/unit/fine-grained-modules.test index 0e859997140a..6a531ced54ba 100644 --- a/test-data/unit/fine-grained-modules.test +++ b/test-data/unit/fine-grained-modules.test @@ -1606,6 +1606,23 @@ class A: pass [out] == +[case testImportStarOverlap] +from b import * +from c import * # type: ignore +[file b.py] +from d import T +[file c.py] +from d import T +[file c.py.2] +from d import T +z = 10 +[file d.py] +from typing import TypeVar +T = TypeVar('T') +[out] +== + + [case testImportPartialAssign] import a [file a.py]