|
19 | 19 | # N.B: we do a quick_and_dirty fixup in both quick_and_dirty mode and
|
20 | 20 | # when fixing up a fine-grained incremental cache load (since there may
|
21 | 21 | # be cross-refs into deleted modules)
|
22 |
| -def fixup_module_pass_one(tree: MypyFile, modules: Dict[str, MypyFile], |
23 |
| - quick_and_dirty: bool) -> None: |
| 22 | +def fixup_module(tree: MypyFile, modules: Dict[str, MypyFile], |
| 23 | + quick_and_dirty: bool) -> None: |
24 | 24 | node_fixer = NodeFixer(modules, quick_and_dirty)
|
25 | 25 | node_fixer.visit_symbol_table(tree.names)
|
26 | 26 |
|
27 | 27 |
|
28 |
| -def fixup_module_pass_two(tree: MypyFile, modules: Dict[str, MypyFile]) -> None: |
29 |
| - compute_all_mros(tree.names, modules) |
30 |
| - |
31 |
| - |
32 |
| -def compute_all_mros(symtab: SymbolTable, modules: Dict[str, MypyFile]) -> None: |
33 |
| - for key, value in symtab.items(): |
34 |
| - if value.kind in (LDEF, MDEF, GDEF) and isinstance(value.node, TypeInfo): |
35 |
| - info = value.node |
36 |
| - info.calculate_mro() |
37 |
| - assert info.mro, "No MRO calculated for %s" % (info.fullname(),) |
38 |
| - compute_all_mros(info.names, modules) |
39 |
| - |
40 |
| - |
41 | 28 | # TODO: Fix up .info when deserializing, i.e. much earlier.
|
42 | 29 | class NodeFixer(NodeVisitor[None]):
|
43 | 30 | current_info = None # type: Optional[TypeInfo]
|
@@ -69,6 +56,10 @@ def visit_type_info(self, info: TypeInfo) -> None:
|
69 | 56 | info.declared_metaclass.accept(self.type_fixer)
|
70 | 57 | if info.metaclass_type:
|
71 | 58 | info.metaclass_type.accept(self.type_fixer)
|
| 59 | + if info._mro_refs: |
| 60 | + info.mro = [lookup_qualified_typeinfo(self.modules, name, self.quick_and_dirty) |
| 61 | + for name in info._mro_refs] |
| 62 | + info._mro_refs = None |
72 | 63 | finally:
|
73 | 64 | self.current_info = save_info
|
74 | 65 |
|
@@ -162,18 +153,12 @@ def visit_instance(self, inst: Instance) -> None:
|
162 | 153 | if type_ref is None:
|
163 | 154 | return # We've already been here.
|
164 | 155 | del inst.type_ref
|
165 |
| - node = lookup_qualified(self.modules, type_ref, self.quick_and_dirty) |
166 |
| - if isinstance(node, TypeInfo): |
167 |
| - inst.type = node |
168 |
| - # TODO: Is this needed or redundant? |
169 |
| - # Also fix up the bases, just in case. |
170 |
| - for base in inst.type.bases: |
171 |
| - if base.type is NOT_READY: |
172 |
| - base.accept(self) |
173 |
| - else: |
174 |
| - # Looks like a missing TypeInfo in quick mode, put something there |
175 |
| - assert self.quick_and_dirty, "Should never get here in normal mode" |
176 |
| - inst.type = stale_info(self.modules) |
| 156 | + inst.type = lookup_qualified_typeinfo(self.modules, type_ref, self.quick_and_dirty) |
| 157 | + # TODO: Is this needed or redundant? |
| 158 | + # Also fix up the bases, just in case. |
| 159 | + for base in inst.type.bases: |
| 160 | + if base.type is NOT_READY: |
| 161 | + base.accept(self) |
177 | 162 | for a in inst.args:
|
178 | 163 | a.accept(self)
|
179 | 164 |
|
@@ -251,6 +236,17 @@ def visit_type_type(self, t: TypeType) -> None:
|
251 | 236 | t.item.accept(self)
|
252 | 237 |
|
253 | 238 |
|
| 239 | +def lookup_qualified_typeinfo(modules: Dict[str, MypyFile], name: str, |
| 240 | + quick_and_dirty: bool) -> TypeInfo: |
| 241 | + node = lookup_qualified(modules, name, quick_and_dirty) |
| 242 | + if isinstance(node, TypeInfo): |
| 243 | + return node |
| 244 | + else: |
| 245 | + # Looks like a missing TypeInfo in quick mode, put something there |
| 246 | + assert quick_and_dirty, "Should never get here in normal mode" |
| 247 | + return stale_info(modules) |
| 248 | + |
| 249 | + |
254 | 250 | def lookup_qualified(modules: Dict[str, MypyFile], name: str,
|
255 | 251 | quick_and_dirty: bool) -> Optional[SymbolNode]:
|
256 | 252 | stnode = lookup_qualified_stnode(modules, name, quick_and_dirty)
|
|
0 commit comments