@@ -6292,22 +6292,37 @@ def record_imported_symbol(self, sym: SymbolTableNode) -> None:
6292
6292
if sym .kind == LDEF or sym .node is None :
6293
6293
return
6294
6294
node = sym .node
6295
- if not node .fullname :
6295
+ if isinstance (node , PlaceholderNode ) or not node .fullname :
6296
+ # This node is not ready yet.
6296
6297
return
6298
+ if node .fullname .startswith (("builtins." , "typing." )):
6299
+ # Skip dependencies on builtins/typing.
6300
+ return
6301
+ # Modules, classes, and type aliases store defining module directly.
6297
6302
if isinstance (node , MypyFile ):
6298
6303
fullname = node .fullname
6299
6304
elif isinstance (node , TypeInfo ):
6300
6305
fullname = node .module_name
6301
6306
elif isinstance (node , TypeAlias ):
6302
6307
fullname = node .module
6303
- elif isinstance (node , (Var , FuncDef , OverloadedFuncDef )) and node .info :
6304
- fullname = node .info .module_name
6308
+ elif isinstance (node , (Var , FuncDef , OverloadedFuncDef , Decorator )):
6309
+ # For functions/variables infer defining module from enclosing class.
6310
+ info = node .var .info if isinstance (node , Decorator ) else node .info
6311
+ if info :
6312
+ fullname = info .module_name
6313
+ else :
6314
+ # global function/variable
6315
+ fullname = node .fullname .rsplit ("." , maxsplit = 1 )[0 ]
6305
6316
else :
6306
- fullname = node .fullname .rsplit ("." )[0 ]
6317
+ # Some nodes (currently only TypeVarLikeExpr subclasses) don't store
6318
+ # module fullname explicitly, infer it from the node fullname iteratively.
6319
+ # TODO: this is not 100% robust for type variables nested within a class
6320
+ # with a name that matches name of a submodule.
6321
+ fullname = node .fullname .rsplit ("." , maxsplit = 1 )[0 ]
6307
6322
if fullname == self .cur_mod_id :
6308
6323
return
6309
6324
while "." in fullname and fullname not in self .modules :
6310
- fullname = fullname .rsplit ("." )[0 ]
6325
+ fullname = fullname .rsplit ("." , maxsplit = 1 )[0 ]
6311
6326
if fullname != self .cur_mod_id :
6312
6327
self .cur_mod_node .module_refs .add (fullname )
6313
6328
0 commit comments