@@ -526,7 +526,10 @@ def __repr__(self):
526526
527527
528528class ClassScope (Scope ):
529- pass
529+ def __init__ (self ):
530+ super ().__init__ ()
531+ # {name: node}
532+ self .indirect_assignments = {}
530533
531534
532535class FunctionScope (Scope ):
@@ -566,9 +569,6 @@ def unused_annotations(self):
566569 if not binding .used and isinstance (binding , Annotation ):
567570 yield name , binding
568571
569- def unused_indirect_assignments (self ):
570- return self .indirect_assignments .items ()
571-
572572
573573class TypeScope (Scope ):
574574 pass
@@ -835,6 +835,10 @@ def checkDeadScopes(self):
835835 which were imported but unused.
836836 """
837837 for scope in self .deadScopes :
838+ if isinstance (scope , (ClassScope , FunctionScope )):
839+ for name , node in scope .indirect_assignments .items ():
840+ self .report (messages .UnusedIndirectAssignment , node , name )
841+
838842 # imports in classes are public members
839843 if isinstance (scope , ClassScope ):
840844 continue
@@ -844,8 +848,6 @@ def checkDeadScopes(self):
844848 self .report (messages .UnusedVariable , binding .source , name )
845849 for name , binding in scope .unused_annotations ():
846850 self .report (messages .UnusedAnnotation , binding .source , name )
847- for name , node in scope .unused_indirect_assignments ():
848- self .report (messages .UnusedIndirectAssignment , node , name )
849851
850852 all_binding = scope .get ('__all__' )
851853 if all_binding and not isinstance (all_binding , ExportBinding ):
@@ -988,7 +990,7 @@ def addBinding(self, node, value):
988990 self .report (messages .RedefinedWhileUnused ,
989991 node , value .name , existing .source )
990992
991- if isinstance (scope , FunctionScope ):
993+ if isinstance (scope , ( ClassScope , FunctionScope ) ):
992994 scope .indirect_assignments .pop (value .name , None )
993995
994996 elif isinstance (existing , Importation ) and value .redefines (existing ):
@@ -1191,7 +1193,7 @@ def on_conditional_branch():
11911193 # be executed.
11921194 return
11931195
1194- if isinstance (self .scope , FunctionScope ):
1196+ if isinstance (self .scope , ( ClassScope , FunctionScope ) ):
11951197 self .scope .indirect_assignments .pop (name , None )
11961198
11971199 if isinstance (self .scope , FunctionScope ) and name in self .scope .globals :
0 commit comments