From 14a85343652f7c69da626fe467f36a02e209aae7 Mon Sep 17 00:00:00 2001 From: Max Moroz Date: Wed, 19 Apr 2017 23:26:18 -0700 Subject: [PATCH] Fix crash when looking up _importlib_modulespec names --- mypy/fixup.py | 3 +++ mypy/semanal.py | 2 ++ 2 files changed, 5 insertions(+) diff --git a/mypy/fixup.py b/mypy/fixup.py index 58c1abad5356..dd3846128db4 100644 --- a/mypy/fixup.py +++ b/mypy/fixup.py @@ -15,6 +15,8 @@ ) from mypy.visitor import NodeVisitor +from mypy.semanal import rev_module_rename_map + def fixup_module_pass_one(tree: MypyFile, modules: Dict[str, MypyFile], quick_and_dirty: bool) -> None: @@ -248,6 +250,7 @@ def lookup_qualified(modules: Dict[str, MypyFile], name: str, def lookup_qualified_stnode(modules: Dict[str, MypyFile], name: str, quick_and_dirty: bool) -> Optional[SymbolTableNode]: + name = rev_module_rename_map.get(name, name) head = name rest = [] while True: diff --git a/mypy/semanal.py b/mypy/semanal.py index c59448bf62e4..6b595c3a0a2f 100644 --- a/mypy/semanal.py +++ b/mypy/semanal.py @@ -120,6 +120,8 @@ '_importlib_modulespec.Loader': 'importlib.abc.Loader' } +rev_module_rename_map = {v: k for (k, v) in module_rename_map.items()} + # Hard coded type promotions (shared between all Python versions). # These add extra ad-hoc edges to the subtyping relation. For example, # int is considered a subtype of float, even though there is no