From 9a05f9c0e249247ae2761ccd33c6ce53fce8b789 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Wed, 16 May 2018 19:10:25 -0400 Subject: [PATCH] Fix an aststrip crash bug Found in Zulip. In some cases (involving errors), two import *s could list overlapping imported_names. --- mypy/server/aststrip.py | 3 ++- test-data/unit/fine-grained-modules.test | 17 +++++++++++++++++ 2 files changed, 19 insertions(+), 1 deletion(-) 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]