diff -r 1b59c4ba121e -r 8cd4d08fa9f6 UtilitiesPython2/py2flakes/checker.py --- a/UtilitiesPython2/py2flakes/checker.py Fri Mar 11 08:55:14 2011 +0100 +++ b/UtilitiesPython2/py2flakes/checker.py Fri Mar 11 16:51:57 2011 +0100 @@ -14,6 +14,7 @@ from py2flakes import messages + class Binding(object): """ Represents the binding of a value to a name. @@ -37,11 +38,13 @@ self.source.lineno, id(self)) + class UnBinding(Binding): ''' Created by the 'del' operator. ''' + class Importation(Binding): """ A binding created by an import statement. @@ -51,11 +54,13 @@ name = name.split('.')[0] super(Importation, self).__init__(name, source) + class Argument(Binding): """ Represents binding a name as an argument. """ + class Assignment(Binding): """ Represents binding a name with an explicit assignment. @@ -65,12 +70,14 @@ Assignments, rather it treats them as simple Bindings. """ + class FunctionDefinition(Binding): """ Represents a function definition. """ pass + class ExportBinding(Binding): """ A binding created by an __all__ assignment. If the names in the list @@ -96,6 +103,7 @@ names.append(node.value) return names + class Scope(dict): """ Class defining the scope base class. @@ -108,12 +116,14 @@ def __init__(self): super(Scope, self).__init__() + class ClassScope(Scope): """ Class representing a name scope for a class. """ pass + class FunctionScope(Scope): """ Class representing a name scope for a function. @@ -122,6 +132,7 @@ super(FunctionScope, self).__init__() self.globals = {} + class ModuleScope(Scope): """ Class representing a name scope for a module. @@ -131,6 +142,7 @@ # Globally defined names which are not attributes of the __builtin__ module. _MAGIC_GLOBALS = ['__file__', '__builtins__'] + class Checker(object): """ Class to check the cleanliness and sanity of Python code. @@ -323,7 +335,6 @@ self.handleChildren(node.body) - def GLOBAL(self, node): """ Keep track of globals declarations. @@ -343,6 +354,7 @@ Process bindings for loop variables. """ vars = [] + def collectLoopVars(n): if hasattr(n, 'name'): vars.append(n.name) @@ -402,7 +414,6 @@ else: self.report(messages.UndefinedName, node.lineno, node.name) - def FUNCTION(self, node): if getattr(node, "decorators", None) is not None: self.handleChildren(node.decorators) @@ -430,6 +441,7 @@ for name in args: self.addBinding(node.lineno, Argument(name, node), reportRedef=False) self.handleNode(node.code, node) + def checkUnusedAssignments(): """ Check to see if any assignments have not been used. @@ -444,7 +456,6 @@ self.deferFunction(runFunction) - def CLASS(self, node): """ Check names used in a class definition, including its decorators, base @@ -460,7 +471,6 @@ self.handleChildren(node.code) self.popScope() - def ASSNAME(self, node): if node.flags == 'OP_DELETE': if isinstance(self.scope, FunctionScope) and node.name in self.scope.globals: