Ticket #2718: unused-in-function-2718-2-progress.diff

File unused-in-function-2718-2-progress.diff, 5.4 kB (added by jml, 1 year ago)

Diff between 2 and 3 -- style changes.

  • pyflakes/checker.py

    old new  
    88from pyflakes import messages 
    99 
    1010 
     11 
    1112class Binding(object): 
    1213    """ 
     14    Represents the binding of a value to a name. 
     15 
     16    The checker uses this to keep track of which names have been bound and 
     17    which names have not. See L{Assignment} for a special type of binding that 
     18    is checked with stricter rules. 
     19 
    1320    @ivar used: pair of (L{Scope}, line-number) indicating the scope and 
    1421                line number that this binding was last used 
    1522    """ 
     23 
    1624    def __init__(self, name, source): 
    1725        self.name = name 
    1826        self.source = source 
    1927        self.used = False 
    2028 
     29 
    2130    def __str__(self): 
    2231        return self.name 
    2332 
     33 
    2434    def __repr__(self): 
    2535        return '<%s object %r from line %r at 0x%x>' % (self.__class__.__name__, 
    2636                                                        self.name, 
    2737                                                        self.source.lineno, 
    2838                                                        id(self)) 
    2939 
     40 
     41 
    3042class UnBinding(Binding): 
    3143    '''Created by the 'del' operator.''' 
    3244 
     
    3648        super(Importation, self).__init__(name, source) 
    3749 
    3850 
     51 
    3952class Argument(Binding): 
    40     pass 
     53    """ 
     54    Represents binding a name as an argument. 
     55    """ 
     56 
    4157 
    4258 
    4359class Assignment(Binding): 
    44     pass 
     60    """ 
     61    Represents binding a name with an explicit assignment. 
     62 
     63    The checker will raise warnings for any Assignment that isn't used. Also, 
     64    the checker does not consider assignments in tuple/list unpacking to be 
     65    Assignments, rather it treats them as simple Bindings. 
     66    """ 
     67 
    4568 
    4669 
    4770class FunctionDefinition(Binding): 
    4871    pass 
    4972 
    5073 
     74 
    5175class Scope(dict): 
    5276    importStarred = False       # set to True when import * is found 
    5377 
     78 
    5479    def __repr__(self): 
    5580        return '<%s at 0x%x %s>' % (self.__class__.__name__, id(self), dict.__repr__(self)) 
    5681 
     82 
    5783    def __init__(self): 
    5884        super(Scope, self).__init__() 
    5985 
     86 
     87 
    6088class ClassScope(Scope): 
    6189    pass 
    6290 
     
    78106    pass 
    79107 
    80108 
     109 
    81110class Checker(object): 
    82111    nodeDepth = 0 
    83112    traceTree = False 
    84113 
    85114    def __init__(self, tree, filename='(none)'): 
    86         self._deferred_functions = [] 
    87         self._deferred_assignments = [] 
     115        self._deferredFunctions = [] 
     116        self._deferredAssignments = [] 
    88117        self.dead_scopes = [] 
    89118        self.messages = [] 
    90119        self.filename = filename 
    91120        self.scopeStack = [ModuleScope()] 
    92121        self.futuresAllowed = True 
    93122        self.handleChildren(tree) 
    94         self._runDeferred(self._deferred_functions) 
    95         self._runDeferred(self._deferred_assignments) 
     123        self._runDeferred(self._deferredFunctions) 
     124        self._runDeferred(self._deferredAssignments) 
    96125        del self.scopeStack[1:] 
    97126        self.popScope() 
    98127        self.check_dead_scopes() 
     
    107136        `callable` is called, the scope at the time this is called will be 
    108137        restored, however it will contain any new bindings added to it. 
    109138        ''' 
    110         self._deferred_functions.append((callable, self.scopeStack[:])) 
     139        self._deferredFunctions.append((callable, self.scopeStack[:])) 
    111140 
    112141 
    113142    def deferAssignment(self, callable): 
     
    115144        Schedule an assignment handler to be called after just before 
    116145        completion. 
    117146        """ 
    118         self._deferred_assignments.append((callable, self.scopeStack[:])) 
     147        self._deferredAssignments.append((callable, self.scopeStack[:])) 
    119148 
    120149 
    121150    def _runDeferred(self, deferred): 
     151        """ 
     152        Run the callables in C{deferred} using their associated scope stack. 
     153        """ 
    122154        for handler, scope in deferred: 
    123155            self.scopeStack = scope 
    124156            handler() 
     
    342374                self.addBinding(node.lineno, Argument(name, node), reportRedef=False) 
    343375            self.handleNode(node.code, node) 
    344376            def checkUnusedAssignments(): 
     377                """ 
     378                Check to see if any assignments have not been used. 
     379                """ 
    345380                for name, binding in self.scope.iteritems(): 
    346381                    if (not binding.used and not name in self.scope.globals 
    347382                        and isinstance(binding, Assignment)): 
  • pyflakes/messages.py

    old new  
    7474 
    7575 
    7676class UnusedVariable(Message): 
     77    """ 
     78    Indicates that a variable has been explicity assigned to but not actually 
     79    used. 
     80    """ 
     81 
    7782    message = 'local variable %r is assigned to but never used' 
    7883    def __init__(self, filename, lineno, names): 
    7984        Message.__init__(self, filename, lineno) 
  • pyflakes/test/test_other.py

    old new  
    188188 
    189189 
    190190    def test_closedOver(self): 
     191        """ 
     192        Don't warn when the assignment is used in an inner function. 
     193        """ 
    191194        self.flakes(''' 
    192195        def barMaker(): 
    193196            foo = 5 
     
    198201 
    199202 
    200203    def test_doubleClosedOver(self): 
     204        """ 
     205        Don't warn when the assignment is used in an inner function, even if 
     206        that inner function itself is in an inner function. 
     207        """ 
    201208        self.flakes(''' 
    202209        def barMaker(): 
    203210            foo = 5 
jethro@divmod.org