4
4
from typing_extensions import Final
5
5
6
6
from mypy .nodes import (
7
- MypyFile , SymbolNode , SymbolTable , SymbolTableNode ,
8
- TypeInfo , FuncDef , OverloadedFuncDef , Decorator , Var ,
9
- TypeVarExpr , ClassDef , Block , TypeAlias ,
7
+ MypyFile , SymbolTable , TypeInfo , FuncDef , OverloadedFuncDef ,
8
+ Decorator , Var , TypeVarExpr , ClassDef , Block , TypeAlias ,
10
9
)
11
10
from mypy .types import (
12
11
CallableType , Instance , Overloaded , TupleType , TypedDictType ,
@@ -58,7 +57,8 @@ def visit_type_info(self, info: TypeInfo) -> None:
58
57
if info .metaclass_type :
59
58
info .metaclass_type .accept (self .type_fixer )
60
59
if info ._mro_refs :
61
- info .mro = [lookup_qualified_typeinfo (self .modules , name , self .allow_missing )
60
+ info .mro = [lookup_fully_qualified_typeinfo (self .modules , name ,
61
+ allow_missing = self .allow_missing )
62
62
for name in info ._mro_refs ]
63
63
info ._mro_refs = None
64
64
finally :
@@ -74,8 +74,8 @@ def visit_symbol_table(self, symtab: SymbolTable, table_fullname: str) -> None:
74
74
if cross_ref in self .modules :
75
75
value .node = self .modules [cross_ref ]
76
76
else :
77
- stnode = lookup_qualified_stnode ( self .modules , cross_ref ,
78
- self .allow_missing )
77
+ stnode = lookup_fully_qualified ( cross_ref , self .modules ,
78
+ raise_on_missing = not self .allow_missing )
79
79
if stnode is not None :
80
80
assert stnode .node is not None , (table_fullname + "." + key , cross_ref )
81
81
value .node = stnode .node
@@ -151,7 +151,8 @@ def visit_instance(self, inst: Instance) -> None:
151
151
if type_ref is None :
152
152
return # We've already been here.
153
153
inst .type_ref = None
154
- inst .type = lookup_qualified_typeinfo (self .modules , type_ref , self .allow_missing )
154
+ inst .type = lookup_fully_qualified_typeinfo (self .modules , type_ref ,
155
+ allow_missing = self .allow_missing )
155
156
# TODO: Is this needed or redundant?
156
157
# Also fix up the bases, just in case.
157
158
for base in inst .type .bases :
@@ -167,7 +168,8 @@ def visit_type_alias_type(self, t: TypeAliasType) -> None:
167
168
if type_ref is None :
168
169
return # We've already been here.
169
170
t .type_ref = None
170
- t .alias = lookup_qualified_alias (self .modules , type_ref , self .allow_missing )
171
+ t .alias = lookup_fully_qualified_alias (self .modules , type_ref ,
172
+ allow_missing = self .allow_missing )
171
173
for a in t .args :
172
174
a .accept (self )
173
175
@@ -228,8 +230,8 @@ def visit_typeddict_type(self, tdt: TypedDictType) -> None:
228
230
it .accept (self )
229
231
if tdt .fallback is not None :
230
232
if tdt .fallback .type_ref is not None :
231
- if lookup_qualified ( self . modules , tdt .fallback .type_ref ,
232
- self .allow_missing ) is None :
233
+ if lookup_fully_qualified ( tdt .fallback .type_ref , self . modules ,
234
+ raise_on_missing = not self .allow_missing ) is None :
233
235
# We reject fake TypeInfos for TypedDict fallbacks because
234
236
# the latter are used in type checking and must be valid.
235
237
tdt .fallback .type_ref = 'typing._TypedDict'
@@ -261,9 +263,10 @@ def visit_type_type(self, t: TypeType) -> None:
261
263
t .item .accept (self )
262
264
263
265
264
- def lookup_qualified_typeinfo (modules : Dict [str , MypyFile ], name : str ,
265
- allow_missing : bool ) -> TypeInfo :
266
- node = lookup_qualified (modules , name , allow_missing )
266
+ def lookup_fully_qualified_typeinfo (modules : Dict [str , MypyFile ], name : str , * ,
267
+ allow_missing : bool ) -> TypeInfo :
268
+ stnode = lookup_fully_qualified (name , modules , raise_on_missing = not allow_missing )
269
+ node = stnode .node if stnode else None
267
270
if isinstance (node , TypeInfo ):
268
271
return node
269
272
else :
@@ -275,9 +278,10 @@ def lookup_qualified_typeinfo(modules: Dict[str, MypyFile], name: str,
275
278
return missing_info (modules )
276
279
277
280
278
- def lookup_qualified_alias (modules : Dict [str , MypyFile ], name : str ,
279
- allow_missing : bool ) -> TypeAlias :
280
- node = lookup_qualified (modules , name , allow_missing )
281
+ def lookup_fully_qualified_alias (modules : Dict [str , MypyFile ], name : str , * ,
282
+ allow_missing : bool ) -> TypeAlias :
283
+ stnode = lookup_fully_qualified (name , modules , raise_on_missing = not allow_missing )
284
+ node = stnode .node if stnode else None
281
285
if isinstance (node , TypeAlias ):
282
286
return node
283
287
else :
@@ -289,20 +293,6 @@ def lookup_qualified_alias(modules: Dict[str, MypyFile], name: str,
289
293
return missing_alias ()
290
294
291
295
292
- def lookup_qualified (modules : Dict [str , MypyFile ], name : str ,
293
- allow_missing : bool ) -> Optional [SymbolNode ]:
294
- stnode = lookup_qualified_stnode (modules , name , allow_missing )
295
- if stnode is None :
296
- return None
297
- else :
298
- return stnode .node
299
-
300
-
301
- def lookup_qualified_stnode (modules : Dict [str , MypyFile ], name : str ,
302
- allow_missing : bool ) -> Optional [SymbolTableNode ]:
303
- return lookup_fully_qualified (name , modules , raise_on_missing = not allow_missing )
304
-
305
-
306
296
_SUGGESTION : Final = "<missing {}: *should* have gone away during fine-grained update>"
307
297
308
298
@@ -312,8 +302,7 @@ def missing_info(modules: Dict[str, MypyFile]) -> TypeInfo:
312
302
dummy_def .fullname = suggestion
313
303
314
304
info = TypeInfo (SymbolTable (), dummy_def , "<missing>" )
315
- obj_type = lookup_qualified (modules , 'builtins.object' , False )
316
- assert isinstance (obj_type , TypeInfo )
305
+ obj_type = lookup_fully_qualified_typeinfo (modules , 'builtins.object' , allow_missing = False )
317
306
info .bases = [Instance (obj_type , [])]
318
307
info .mro = [info , obj_type ]
319
308
return info
0 commit comments