--- a/Utilities/py3flakes/checker.py Fri Mar 11 08:55:14 2011 +0100 +++ b/Utilities/py3flakes/checker.py Fri Mar 11 16:51:57 2011 +0100 @@ -13,6 +13,7 @@ from . import messages + class Binding(object): """ Represents the binding of a value to a name. @@ -36,11 +37,13 @@ self.source.lineno, id(self)) + class UnBinding(Binding): ''' Created by the 'del' operator. ''' + class Importation(Binding): """ A binding created by an import statement. @@ -50,11 +53,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. @@ -64,12 +69,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 @@ -97,6 +104,7 @@ names.append(node.n) return names + class Scope(dict): """ Class defining the scope base class. @@ -110,12 +118,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. @@ -124,6 +134,7 @@ super(FunctionScope, self).__init__() self.globals = {} + class ModuleScope(Scope): """ Class representing a name scope for a module. @@ -133,6 +144,7 @@ # Globally defined names which are not attributes of the builtins module. _MAGIC_GLOBALS = ['__file__', '__builtins__'] + class Checker(object): """ Class to check the cleanliness and sanity of Python code. @@ -140,7 +152,7 @@ nodeDepth = 0 traceTree = False - def __init__(self, module, filename = '(none)'): + def __init__(self, module, filename='(none)'): """ Constructor @@ -301,7 +313,7 @@ # additional node types COMPREHENSION = KEYWORD = handleChildren - def addBinding(self, lineno, value, reportRedef = True): + def addBinding(self, lineno, value, reportRedef=True): ''' Called when a binding is altered. @@ -367,6 +379,7 @@ Process bindings for loop variables. """ vars = [] + def collectLoopVars(n): if isinstance(n, ast.Name): vars.append(n.id) @@ -619,7 +632,7 @@ def IMPORTFROM(self, node): if node.module == '__future__': if not self.futuresAllowed: - self.report(messages.LateFutureImport, node.lineno, + self.report(messages.LateFutureImport, node.lineno, [n.name for n in node.names]) else: self.futuresAllowed = False