@@ -769,7 +769,6 @@ def __init__(self, tree, filename='(none)', builtins=None,
769
769
withDoctest = 'PYFLAKES_DOCTEST' in os .environ , file_tokens = ()):
770
770
self ._nodeHandlers = {}
771
771
self ._deferredFunctions = []
772
- self ._deferredAssignments = []
773
772
self .deadScopes = []
774
773
self .messages = []
775
774
self .filename = filename
@@ -790,11 +789,8 @@ def __init__(self, tree, filename='(none)', builtins=None,
790
789
# Set _deferredFunctions to None so that deferFunction will fail
791
790
# noisily if called after we've run through the deferred functions.
792
791
self ._deferredFunctions = None
793
- self .runDeferred (self ._deferredAssignments )
794
- # Set _deferredAssignments to None so that deferAssignment will fail
795
- # noisily if called after we've run through the deferred assignments.
796
- self ._deferredAssignments = None
797
792
del self .scopeStack [1 :]
793
+
798
794
self .popScope ()
799
795
self .checkDeadScopes ()
800
796
@@ -815,13 +811,6 @@ def deferFunction(self, callable):
815
811
"""
816
812
self ._deferredFunctions .append ((callable , self .scopeStack [:], self .offset ))
817
813
818
- def deferAssignment (self , callable ):
819
- """
820
- Schedule an assignment handler to be called just after deferred
821
- function handlers.
822
- """
823
- self ._deferredAssignments .append ((callable , self .scopeStack [:], self .offset ))
824
-
825
814
def runDeferred (self , deferred ):
826
815
"""
827
816
Run the callables in C{deferred} using their associated scope stack.
@@ -879,6 +868,12 @@ def checkDeadScopes(self):
879
868
if isinstance (scope , ClassScope ):
880
869
continue
881
870
871
+ if isinstance (scope , FunctionScope ):
872
+ for name , binding in scope .unused_assignments ():
873
+ self .report (messages .UnusedVariable , binding .source , name )
874
+ for name , binding in scope .unused_annotations ():
875
+ self .report (messages .UnusedAnnotation , binding .source , name )
876
+
882
877
all_binding = scope .get ('__all__' )
883
878
if all_binding and not isinstance (all_binding , ExportBinding ):
884
879
all_binding = None
@@ -1991,28 +1986,10 @@ def LAMBDA(self, node):
1991
1986
self .handleNode (default , node )
1992
1987
1993
1988
def runFunction ():
1994
-
1995
1989
self .pushScope ()
1996
1990
1997
1991
self .handleChildren (node , omit = ['decorator_list' , 'returns' ])
1998
1992
1999
- def check_unused_assignments ():
2000
- """
2001
- Check to see if any assignments have not been used.
2002
- """
2003
- for name , binding in self .scope .unused_assignments ():
2004
- self .report (messages .UnusedVariable , binding .source , name )
2005
-
2006
- def check_unused_annotations ():
2007
- """
2008
- Check to see if any annotations have not been used.
2009
- """
2010
- for name , binding in self .scope .unused_annotations ():
2011
- self .report (messages .UnusedAnnotation , binding .source , name )
2012
-
2013
- self .deferAssignment (check_unused_assignments )
2014
- self .deferAssignment (check_unused_annotations )
2015
-
2016
1993
self .popScope ()
2017
1994
2018
1995
self .deferFunction (runFunction )
0 commit comments