Skip to content

Commit a6a53e5

Browse files
authored
Fix incremental mode when non-compiled classes are imported (#8498)
1 parent 41fd871 commit a6a53e5

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

mypyc/irbuild/prepare.py

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from mypy.nodes import (
44
MypyFile, TypeInfo, FuncDef, ClassDef, Decorator, OverloadedFuncDef, MemberExpr, Var,
5-
Expression, ARG_STAR, ARG_STAR2
5+
Expression, SymbolNode, ARG_STAR, ARG_STAR2
66
)
77
from mypy.types import Type
88
from mypy.build import Graph
@@ -63,13 +63,17 @@ def build_type_map(mapper: Mapper,
6363
# TODO: what else?
6464

6565

66+
def is_from_module(node: SymbolNode, module: MypyFile) -> bool:
67+
return node.fullname == module.fullname + '.' + node.name
68+
69+
6670
def load_type_map(mapper: 'Mapper',
6771
modules: List[MypyFile],
6872
deser_ctx: DeserMaps) -> None:
6973
"""Populate a Mapper with deserialized IR from a list of modules."""
7074
for module in modules:
7175
for name, node in module.names.items():
72-
if isinstance(node.node, TypeInfo):
76+
if isinstance(node.node, TypeInfo) and is_from_module(node.node, module):
7377
ir = deser_ctx.classes[node.node.fullname]
7478
mapper.type_to_ir[node.node] = ir
7579
mapper.func_to_decl[node.node] = ir.ctor
@@ -86,7 +90,7 @@ def get_module_func_defs(module: MypyFile) -> Iterable[FuncDef]:
8690
# aliases. The best way to do this seems to be by
8791
# checking that the fullname matches.
8892
if (isinstance(node.node, (FuncDef, Decorator, OverloadedFuncDef))
89-
and node.fullname == module.fullname + '.' + name):
93+
and is_from_module(node.node, module)):
9094
yield get_func_def(node.node)
9195

9296

mypyc/test-data/run-multimodule.test

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,12 +604,14 @@ assert non_native.foo() == 0
604604

605605
[file other_a.py]
606606
from other_b import z
607+
from typing import Iterable
607608

608609
class A:
609610
def __init__(self) -> None:
610611
self.y = z
611612
[file other_a.py.2]
612613
from other_b import z
614+
from typing import Iterable
613615

614616
class A:
615617
def __init__(self) -> None:

0 commit comments

Comments
 (0)