@@ -192,7 +192,7 @@ def visit_class_def(self, tdef: ClassDef) -> None:
192192 self .analyze (tdef .analyzed .info .typeddict_type , tdef .analyzed , warn = True )
193193 elif isinstance (tdef .analyzed , NamedTupleExpr ):
194194 self .analyze (tdef .analyzed .info .tuple_type , tdef .analyzed , warn = True )
195- self .analyze_info (tdef .analyzed .info )
195+ self .analyze_synthetic_info (tdef .analyzed .info )
196196 super ().visit_class_def (tdef )
197197 self .analyze_symbol_table (tdef .info .names )
198198 self .scope .leave ()
@@ -273,7 +273,7 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
273273 if analyzed .info :
274274 # Currently NewTypes only have __init__, but to be future proof,
275275 # we analyze all symbols.
276- self .analyze_info (analyzed .info )
276+ self .analyze_synthetic_info (analyzed .info )
277277 if analyzed .info and analyzed .info .mro :
278278 analyzed .info .mro = [] # Force recomputation
279279 self .sem .calculate_class_mro (analyzed .info .defn )
@@ -288,7 +288,7 @@ def visit_assignment_stmt(self, s: AssignmentStmt) -> None:
288288 self .analyze (analyzed .info .typeddict_type , analyzed , warn = True )
289289 if isinstance (analyzed , NamedTupleExpr ):
290290 self .analyze (analyzed .info .tuple_type , analyzed , warn = True )
291- self .analyze_info (analyzed .info )
291+ self .analyze_synthetic_info (analyzed .info )
292292 if isinstance (s .lvalues [0 ], RefExpr ) and isinstance (s .lvalues [0 ].node , Var ):
293293 self .analyze (s .lvalues [0 ].node .type , s .lvalues [0 ].node )
294294 # Subclass attribute assignments with no type annotation should be
@@ -472,12 +472,18 @@ def patch2() -> None:
472472
473473 self .patches .append ((PRIORITY_TYPEVAR_VALUES , self .make_scoped_patch (patch2 )))
474474
475- def analyze_info (self , info : TypeInfo ) -> None :
475+ def analyze_synthetic_info (self , info : TypeInfo ) -> None :
476476 # Similar to above but for nodes with synthetic TypeInfos (NamedTuple and NewType).
477477 for name in info .names :
478478 sym = info .names [name ]
479479 if isinstance (sym .node , (FuncDef , Decorator )):
480+ # Since we are analyzing a synthetic type info, the methods there
481+ # are not real independent targets, and should be processed when
482+ # the enclosing synthetic type is processed.
483+ old_recurse = self .recurse_into_functions
484+ self .recurse_into_functions = True
480485 self .accept (sym .node )
486+ self .recurse_into_functions = old_recurse
481487 if isinstance (sym .node , Var ):
482488 self .analyze (sym .node .type , sym .node )
483489
0 commit comments