|
5 | 5 | from mypy.nodes import (
|
6 | 6 | MypyFile, SymbolNode, SymbolTable, SymbolTableNode,
|
7 | 7 | TypeInfo, FuncDef, OverloadedFuncDef, Decorator, Var,
|
8 |
| - TypeVarExpr, ClassDef, |
| 8 | + TypeVarExpr, ClassDef, Block, |
9 | 9 | LDEF, MDEF, GDEF
|
10 | 10 | )
|
11 | 11 | from mypy.types import (
|
@@ -90,6 +90,11 @@ def visit_symbol_table(self, symtab: SymbolTable) -> None:
|
90 | 90 | value.type_override = stnode.type_override
|
91 | 91 | elif not self.quick_and_dirty:
|
92 | 92 | assert stnode is not None, "Could not find cross-ref %s" % (cross_ref,)
|
| 93 | + else: |
| 94 | + # We have a missing crossref in quick mode, need to put something |
| 95 | + value.node = stale_info() |
| 96 | + if value.type_override is not None: |
| 97 | + value.type_override.accept(self.type_fixer) |
93 | 98 | else:
|
94 | 99 | if isinstance(value.node, TypeInfo):
|
95 | 100 | # TypeInfo has no accept(). TODO: Add it?
|
@@ -162,6 +167,10 @@ def visit_instance(self, inst: Instance) -> None:
|
162 | 167 | for base in inst.type.bases:
|
163 | 168 | if base.type is NOT_READY:
|
164 | 169 | base.accept(self)
|
| 170 | + else: |
| 171 | + # Looks like a missing TypeInfo in quick mode, put something there |
| 172 | + assert self.quick_and_dirty, "Should never get here in normal mode" |
| 173 | + inst.type = stale_info() |
165 | 174 | for a in inst.args:
|
166 | 175 | a.accept(self)
|
167 | 176 |
|
@@ -267,12 +276,23 @@ def lookup_qualified_stnode(modules: Dict[str, MypyFile], name: str,
|
267 | 276 | return None
|
268 | 277 | key = rest.pop()
|
269 | 278 | if key not in names:
|
| 279 | + if not quick_and_dirty: |
| 280 | + assert key in names, "Cannot find %s for %s" % (key, name) |
270 | 281 | return None
|
271 |
| - elif not quick_and_dirty: |
272 |
| - assert key in names, "Cannot find %s for %s" % (key, name) |
273 | 282 | stnode = names[key]
|
274 | 283 | if not rest:
|
275 | 284 | return stnode
|
276 | 285 | node = stnode.node
|
277 | 286 | assert isinstance(node, TypeInfo)
|
278 | 287 | names = node.names
|
| 288 | + |
| 289 | + |
| 290 | +def stale_info() -> TypeInfo: |
| 291 | + suggestion = "<stale cache: consider running mypy without --quick>" |
| 292 | + dummy_def = ClassDef(suggestion, Block([])) |
| 293 | + dummy_def.fullname = suggestion |
| 294 | + |
| 295 | + info = TypeInfo(SymbolTable(), dummy_def, "<stale>") |
| 296 | + info.mro = [info] |
| 297 | + info.bases = [] |
| 298 | + return info |
0 commit comments