44from typing_extensions import Final
55
66from 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 ,
109)
1110from mypy .types import (
1211 CallableType , Instance , Overloaded , TupleType , TypedDictType ,
@@ -58,7 +57,8 @@ def visit_type_info(self, info: TypeInfo) -> None:
5857 if info .metaclass_type :
5958 info .metaclass_type .accept (self .type_fixer )
6059 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 )
6262 for name in info ._mro_refs ]
6363 info ._mro_refs = None
6464 finally :
@@ -74,8 +74,8 @@ def visit_symbol_table(self, symtab: SymbolTable, table_fullname: str) -> None:
7474 if cross_ref in self .modules :
7575 value .node = self .modules [cross_ref ]
7676 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 )
7979 if stnode is not None :
8080 assert stnode .node is not None , (table_fullname + "." + key , cross_ref )
8181 value .node = stnode .node
@@ -151,7 +151,8 @@ def visit_instance(self, inst: Instance) -> None:
151151 if type_ref is None :
152152 return # We've already been here.
153153 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 )
155156 # TODO: Is this needed or redundant?
156157 # Also fix up the bases, just in case.
157158 for base in inst .type .bases :
@@ -167,7 +168,8 @@ def visit_type_alias_type(self, t: TypeAliasType) -> None:
167168 if type_ref is None :
168169 return # We've already been here.
169170 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 )
171173 for a in t .args :
172174 a .accept (self )
173175
@@ -228,8 +230,8 @@ def visit_typeddict_type(self, tdt: TypedDictType) -> None:
228230 it .accept (self )
229231 if tdt .fallback is not None :
230232 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 :
233235 # We reject fake TypeInfos for TypedDict fallbacks because
234236 # the latter are used in type checking and must be valid.
235237 tdt .fallback .type_ref = 'typing._TypedDict'
@@ -261,9 +263,10 @@ def visit_type_type(self, t: TypeType) -> None:
261263 t .item .accept (self )
262264
263265
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
267270 if isinstance (node , TypeInfo ):
268271 return node
269272 else :
@@ -275,9 +278,10 @@ def lookup_qualified_typeinfo(modules: Dict[str, MypyFile], name: str,
275278 return missing_info (modules )
276279
277280
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
281285 if isinstance (node , TypeAlias ):
282286 return node
283287 else :
@@ -289,20 +293,6 @@ def lookup_qualified_alias(modules: Dict[str, MypyFile], name: str,
289293 return missing_alias ()
290294
291295
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-
306296_SUGGESTION : Final = "<missing {}: *should* have gone away during fine-grained update>"
307297
308298
@@ -312,8 +302,7 @@ def missing_info(modules: Dict[str, MypyFile]) -> TypeInfo:
312302 dummy_def .fullname = suggestion
313303
314304 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 )
317306 info .bases = [Instance (obj_type , [])]
318307 info .mro = [info , obj_type ]
319308 return info
0 commit comments