Skip to content

Commit

Permalink
Fix incremental mode when non-compiled classes are imported (#8498)
Browse files Browse the repository at this point in the history
  • Loading branch information
msullivan committed Mar 5, 2020
1 parent 41fd871 commit a6a53e5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
10 changes: 7 additions & 3 deletions mypyc/irbuild/prepare.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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)


Expand Down
2 changes: 2 additions & 0 deletions mypyc/test-data/run-multimodule.test
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down

0 comments on commit a6a53e5

Please sign in to comment.