16
16
from mypy .lookup import lookup_fully_qualified
17
17
18
18
19
- # N.B: we do a quick_and_dirty fixup in both quick_and_dirty mode and
20
- # when fixing up a fine-grained incremental cache load (since there may
21
- # be cross-refs into deleted modules)
19
+ # N.B: we do a allow_missing fixup when fixing up a fine-grained
20
+ # incremental cache load (since there may be cross-refs into deleted
21
+ # modules)
22
22
def fixup_module (tree : MypyFile , modules : Dict [str , MypyFile ],
23
- quick_and_dirty : bool ) -> None :
24
- node_fixer = NodeFixer (modules , quick_and_dirty )
23
+ allow_missing : bool ) -> None :
24
+ node_fixer = NodeFixer (modules , allow_missing )
25
25
node_fixer .visit_symbol_table (tree .names )
26
26
27
27
28
28
# TODO: Fix up .info when deserializing, i.e. much earlier.
29
29
class NodeFixer (NodeVisitor [None ]):
30
30
current_info = None # type: Optional[TypeInfo]
31
31
32
- def __init__ (self , modules : Dict [str , MypyFile ], quick_and_dirty : bool ) -> None :
32
+ def __init__ (self , modules : Dict [str , MypyFile ], allow_missing : bool ) -> None :
33
33
self .modules = modules
34
- self .quick_and_dirty = quick_and_dirty
35
- self .type_fixer = TypeFixer (self .modules , quick_and_dirty )
34
+ self .allow_missing = allow_missing
35
+ self .type_fixer = TypeFixer (self .modules , allow_missing )
36
36
37
37
# NOTE: This method isn't (yet) part of the NodeVisitor API.
38
38
def visit_type_info (self , info : TypeInfo ) -> None :
@@ -57,7 +57,7 @@ def visit_type_info(self, info: TypeInfo) -> None:
57
57
if info .metaclass_type :
58
58
info .metaclass_type .accept (self .type_fixer )
59
59
if info ._mro_refs :
60
- info .mro = [lookup_qualified_typeinfo (self .modules , name , self .quick_and_dirty )
60
+ info .mro = [lookup_qualified_typeinfo (self .modules , name , self .allow_missing )
61
61
for name in info ._mro_refs ]
62
62
info ._mro_refs = None
63
63
finally :
@@ -74,14 +74,14 @@ def visit_symbol_table(self, symtab: SymbolTable) -> None:
74
74
value .node = self .modules [cross_ref ]
75
75
else :
76
76
stnode = lookup_qualified_stnode (self .modules , cross_ref ,
77
- self .quick_and_dirty )
77
+ self .allow_missing )
78
78
if stnode is not None :
79
79
value .node = stnode .node
80
- elif not self .quick_and_dirty :
80
+ elif not self .allow_missing :
81
81
assert stnode is not None , "Could not find cross-ref %s" % (cross_ref ,)
82
82
else :
83
- # We have a missing crossref in quick mode, need to put something
84
- value .node = stale_info (self .modules )
83
+ # We have a missing crossref in allow missing mode, need to put something
84
+ value .node = missing_info (self .modules )
85
85
else :
86
86
if isinstance (value .node , TypeInfo ):
87
87
# TypeInfo has no accept(). TODO: Add it?
@@ -137,17 +137,17 @@ def visit_type_alias(self, a: TypeAlias) -> None:
137
137
138
138
139
139
class TypeFixer (TypeVisitor [None ]):
140
- def __init__ (self , modules : Dict [str , MypyFile ], quick_and_dirty : bool ) -> None :
140
+ def __init__ (self , modules : Dict [str , MypyFile ], allow_missing : bool ) -> None :
141
141
self .modules = modules
142
- self .quick_and_dirty = quick_and_dirty
142
+ self .allow_missing = allow_missing
143
143
144
144
def visit_instance (self , inst : Instance ) -> None :
145
145
# TODO: Combine Instances that are exactly the same?
146
146
type_ref = inst .type_ref
147
147
if type_ref is None :
148
148
return # We've already been here.
149
149
inst .type_ref = None
150
- inst .type = lookup_qualified_typeinfo (self .modules , type_ref , self .quick_and_dirty )
150
+ inst .type = lookup_qualified_typeinfo (self .modules , type_ref , self .allow_missing )
151
151
# TODO: Is this needed or redundant?
152
152
# Also fix up the bases, just in case.
153
153
for base in inst .type .bases :
@@ -236,39 +236,39 @@ def visit_type_type(self, t: TypeType) -> None:
236
236
237
237
238
238
def lookup_qualified_typeinfo (modules : Dict [str , MypyFile ], name : str ,
239
- quick_and_dirty : bool ) -> TypeInfo :
240
- node = lookup_qualified (modules , name , quick_and_dirty )
239
+ allow_missing : bool ) -> TypeInfo :
240
+ node = lookup_qualified (modules , name , allow_missing )
241
241
if isinstance (node , TypeInfo ):
242
242
return node
243
243
else :
244
- # Looks like a missing TypeInfo in quick mode , put something there
245
- assert quick_and_dirty , "Should never get here in normal mode," \
246
- " got {}:{} instead of TypeInfo" .format (type (node ).__name__ ,
247
- node .fullname () if node
248
- else '' )
249
- return stale_info (modules )
244
+ # Looks like a missing TypeInfo during an initial daemon load , put something there
245
+ assert allow_missing , "Should never get here in normal mode," \
246
+ " got {}:{} instead of TypeInfo" .format (type (node ).__name__ ,
247
+ node .fullname () if node
248
+ else '' )
249
+ return missing_info (modules )
250
250
251
251
252
252
def lookup_qualified (modules : Dict [str , MypyFile ], name : str ,
253
- quick_and_dirty : bool ) -> Optional [SymbolNode ]:
254
- stnode = lookup_qualified_stnode (modules , name , quick_and_dirty )
253
+ allow_missing : bool ) -> Optional [SymbolNode ]:
254
+ stnode = lookup_qualified_stnode (modules , name , allow_missing )
255
255
if stnode is None :
256
256
return None
257
257
else :
258
258
return stnode .node
259
259
260
260
261
261
def lookup_qualified_stnode (modules : Dict [str , MypyFile ], name : str ,
262
- quick_and_dirty : bool ) -> Optional [SymbolTableNode ]:
263
- return lookup_fully_qualified (name , modules , raise_on_missing = not quick_and_dirty )
262
+ allow_missing : bool ) -> Optional [SymbolTableNode ]:
263
+ return lookup_fully_qualified (name , modules , raise_on_missing = not allow_missing )
264
264
265
265
266
- def stale_info (modules : Dict [str , MypyFile ]) -> TypeInfo :
267
- suggestion = "<stale cache: consider running mypy without --quick >"
266
+ def missing_info (modules : Dict [str , MypyFile ]) -> TypeInfo :
267
+ suggestion = "<missing info: *should* have gone away during fine-grained update >"
268
268
dummy_def = ClassDef (suggestion , Block ([]))
269
269
dummy_def .fullname = suggestion
270
270
271
- info = TypeInfo (SymbolTable (), dummy_def , "<stale >" )
271
+ info = TypeInfo (SymbolTable (), dummy_def , "<missing >" )
272
272
obj_type = lookup_qualified (modules , 'builtins.object' , False )
273
273
assert isinstance (obj_type , TypeInfo )
274
274
info .bases = [Instance (obj_type , [])]
0 commit comments