@@ -526,7 +526,10 @@ def __repr__(self):
526
526
527
527
528
528
class ClassScope (Scope ):
529
- pass
529
+ def __init__ (self ):
530
+ super ().__init__ ()
531
+ # {name: node}
532
+ self .indirect_assignments = {}
530
533
531
534
532
535
class FunctionScope (Scope ):
@@ -566,9 +569,6 @@ def unused_annotations(self):
566
569
if not binding .used and isinstance (binding , Annotation ):
567
570
yield name , binding
568
571
569
- def unused_indirect_assignments (self ):
570
- return self .indirect_assignments .items ()
571
-
572
572
573
573
class TypeScope (Scope ):
574
574
pass
@@ -835,6 +835,10 @@ def checkDeadScopes(self):
835
835
which were imported but unused.
836
836
"""
837
837
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
+
838
842
# imports in classes are public members
839
843
if isinstance (scope , ClassScope ):
840
844
continue
@@ -844,8 +848,6 @@ def checkDeadScopes(self):
844
848
self .report (messages .UnusedVariable , binding .source , name )
845
849
for name , binding in scope .unused_annotations ():
846
850
self .report (messages .UnusedAnnotation , binding .source , name )
847
- for name , node in scope .unused_indirect_assignments ():
848
- self .report (messages .UnusedIndirectAssignment , node , name )
849
851
850
852
all_binding = scope .get ('__all__' )
851
853
if all_binding and not isinstance (all_binding , ExportBinding ):
@@ -988,7 +990,7 @@ def addBinding(self, node, value):
988
990
self .report (messages .RedefinedWhileUnused ,
989
991
node , value .name , existing .source )
990
992
991
- if isinstance (scope , FunctionScope ):
993
+ if isinstance (scope , ( ClassScope , FunctionScope ) ):
992
994
scope .indirect_assignments .pop (value .name , None )
993
995
994
996
elif isinstance (existing , Importation ) and value .redefines (existing ):
@@ -1191,7 +1193,7 @@ def on_conditional_branch():
1191
1193
# be executed.
1192
1194
return
1193
1195
1194
- if isinstance (self .scope , FunctionScope ):
1196
+ if isinstance (self .scope , ( ClassScope , FunctionScope ) ):
1195
1197
self .scope .indirect_assignments .pop (name , None )
1196
1198
1197
1199
if isinstance (self .scope , FunctionScope ) and name in self .scope .globals :
0 commit comments