1616 TypeApplication ,
1717 TypedDictExpr ,
1818 TypeFormExpr ,
19+ TypeInfo ,
1920 TypeVarExpr ,
2021 Var ,
2122 WithStmt ,
@@ -41,15 +42,29 @@ def visit_func(self, o: FuncItem, /) -> None:
4142 self .visit_optional_type (o .type )
4243
4344 def visit_class_def (self , o : ClassDef , / ) -> None :
44- # TODO: Should we visit generated methods/variables as well, either here or in
45- # TraverserVisitor?
4645 super ().visit_class_def (o )
47- info = o .info
48- if info :
49- for base in info .bases :
50- base .accept (self )
51- if info .special_alias :
52- info .special_alias .accept (self )
46+ if o .info :
47+ self .process_type_info (o .info )
48+
49+ def process_type_info (self , info : TypeInfo ) -> None :
50+ # TODO: Should we visit generated methods/variables as well?
51+ # We should for methods generated by us (see below). But it is less clear for
52+ # 3rd party plugin generated methods (since we don't want to emit errors there).
53+ for base in info .bases :
54+ base .accept (self )
55+ if info .special_alias :
56+ # We need to accept all types that are conceptually identical like special
57+ # alias target and corresponding tuple_type or typeddict_type, since those
58+ # may be copies, and not the same object.
59+ info .special_alias .accept (self )
60+ if info .tuple_type :
61+ info .tuple_type .accept (self )
62+ if info .typeddict_type :
63+ info .typeddict_type .accept (self )
64+ if info .is_named_tuple or info .is_newtype :
65+ for sym in info .names .values ():
66+ if sym .plugin_generated and sym .node :
67+ sym .node .accept (self )
5368
5469 def visit_type_alias_expr (self , o : TypeAliasExpr , / ) -> None :
5570 super ().visit_type_alias_expr (o )
@@ -64,19 +79,20 @@ def visit_type_var_expr(self, o: TypeVarExpr, /) -> None:
6479
6580 def visit_typeddict_expr (self , o : TypedDictExpr , / ) -> None :
6681 super ().visit_typeddict_expr (o )
67- self .visit_optional_type (o .info . typeddict_type )
82+ self .process_type_info (o .info )
6883
6984 def visit_namedtuple_expr (self , o : NamedTupleExpr , / ) -> None :
7085 super ().visit_namedtuple_expr (o )
71- assert o .info .tuple_type
72- o .info .tuple_type .accept (self )
86+ self .process_type_info (o .info )
7387
7488 def visit__promote_expr (self , o : PromoteExpr , / ) -> None :
7589 super ().visit__promote_expr (o )
7690 o .type .accept (self )
7791
7892 def visit_newtype_expr (self , o : NewTypeExpr , / ) -> None :
7993 super ().visit_newtype_expr (o )
94+ if o .info :
95+ self .process_type_info (o .info )
8096 self .visit_optional_type (o .old_type )
8197
8298 # Statements
0 commit comments