From dddd8bf24a1b68d0aa4cd5f0e1c4715c9c139900 Mon Sep 17 00:00:00 2001 From: "Michael J. Sullivan" Date: Thu, 5 Mar 2020 11:56:03 -0800 Subject: [PATCH] Fix incremental mode when non-compiled classes are imported --- mypyc/irbuild/prepare.py | 10 +++++++--- mypyc/test-data/run-multimodule.test | 2 ++ 2 files changed, 9 insertions(+), 3 deletions(-) diff --git a/mypyc/irbuild/prepare.py b/mypyc/irbuild/prepare.py index c1110cccc85b..8069cbd29d4c 100644 --- a/mypyc/irbuild/prepare.py +++ b/mypyc/irbuild/prepare.py @@ -2,7 +2,7 @@ from mypy.nodes import ( MypyFile, TypeInfo, FuncDef, ClassDef, Decorator, OverloadedFuncDef, MemberExpr, Var, - Expression, ARG_STAR, ARG_STAR2 + Expression, SymbolNode, ARG_STAR, ARG_STAR2 ) from mypy.types import Type from mypy.build import Graph @@ -63,13 +63,17 @@ def build_type_map(mapper: Mapper, # TODO: what else? +def is_from_module(node: SymbolNode, module: MypyFile) -> bool: + return node.fullname == module.fullname + '.' + node.name + + def load_type_map(mapper: 'Mapper', modules: List[MypyFile], deser_ctx: DeserMaps) -> None: """Populate a Mapper with deserialized IR from a list of modules.""" for module in modules: for name, node in module.names.items(): - if isinstance(node.node, TypeInfo): + if isinstance(node.node, TypeInfo) and is_from_module(node.node, module): ir = deser_ctx.classes[node.node.fullname] mapper.type_to_ir[node.node] = ir mapper.func_to_decl[node.node] = ir.ctor @@ -86,7 +90,7 @@ def get_module_func_defs(module: MypyFile) -> Iterable[FuncDef]: # aliases. The best way to do this seems to be by # checking that the fullname matches. if (isinstance(node.node, (FuncDef, Decorator, OverloadedFuncDef)) - and node.fullname == module.fullname + '.' + name): + and is_from_module(node.node, module)): yield get_func_def(node.node) diff --git a/mypyc/test-data/run-multimodule.test b/mypyc/test-data/run-multimodule.test index 83fc02a86c1d..352611ce0cc4 100644 --- a/mypyc/test-data/run-multimodule.test +++ b/mypyc/test-data/run-multimodule.test @@ -604,12 +604,14 @@ assert non_native.foo() == 0 [file other_a.py] from other_b import z +from typing import Iterable class A: def __init__(self) -> None: self.y = z [file other_a.py.2] from other_b import z +from typing import Iterable class A: def __init__(self) -> None: