public
Description: faster smurfier pyflakes using _ast instead of compiler
Homepage:
Clone URL: git://github.com/kevinw/pyflakes.git
* Added a "builtins" argument to pyflakes.checker.Checker, for passing a list of 
strings that will also be treated as builtins.

* Fixed a bug where the "iter" node in a for loop (the thing you're iterating 
over) wouldn't be traversed.

* Fixed a bug where the type part of an except block wasn't traversed.
kevinw (author)
Wed Nov 19 15:38:18 -0800 2008
commit  bdc1acde85df3bf0a8f5ef1ec26e9121667c9d0a
tree    cb4405071cc1f060e542c96208514cbad36f7a21
parent  2bbf8a46cee0301c39abddb29fc0838f7b5c3ea5
...
6
7
8
9
10
11
12
13
14
15
16
17
18
19
...
78
79
80
81
 
82
83
84
...
87
88
89
 
90
91
92
...
153
154
155
 
 
156
157
158
...
219
220
221
222
 
223
224
225
...
302
303
304
305
 
306
307
308
...
370
371
372
 
 
 
 
 
 
 
 
 
 
...
6
7
8
 
 
 
 
 
 
 
 
9
10
11
...
70
71
72
 
73
74
75
76
...
79
80
81
82
83
84
85
...
146
147
148
149
150
151
152
153
...
214
215
216
 
217
218
219
220
...
297
298
299
 
300
301
302
303
...
365
366
367
368
369
370
371
372
373
374
375
376
377
0
@@ -6,14 +6,6 @@ import __builtin__
0
 allowed_before_future = (ast.Module, ast.ImportFrom, ast.Expr, ast.Str)
0
 defined_names = set(('__file__',))
0
 
0
-def is_builtin(name):
0
-    if hasattr(__builtin__, name):
0
-        return True
0
-    if name in defined_names:
0
-        return True
0
-
0
-    return False
0
-
0
 class Binding(object):
0
     """
0
     @ivar used: pair of (L{Scope}, line-number) indicating the scope and
0
@@ -78,7 +70,7 @@ class ModuleScope(Scope):
0
     pass
0
 
0
 class Checker(ast.NodeVisitor):
0
-    def __init__(self, tree, filename='(none)'):
0
+    def __init__(self, tree, filename='(none)', builtins = None):
0
         ast.NodeVisitor.__init__(self)
0
 
0
         self.deferred = []
0
@@ -87,6 +79,7 @@ class Checker(ast.NodeVisitor):
0
         self.filename = filename
0
         self.scope_stack = [ModuleScope()]
0
         self.futures_allowed = True
0
+        self.builtins = frozenset(builtins or [])
0
 
0
         self.visit(tree)
0
         for handler, scope in self.deferred:
0
@@ -153,6 +146,8 @@ class Checker(ast.NodeVisitor):
0
         '''
0
         Process bindings for loop variables.
0
         '''
0
+        self.visit_nodes(node.iter)
0
+
0
         for var in self.flatten(node.target):
0
             upval = self.scope.get(var.id)
0
             if isinstance(upval, Importation) and upval.used:
0
@@ -219,7 +214,7 @@ class Checker(ast.NodeVisitor):
0
         try:
0
             self.scope_stack[0][node.id].used = (scope, node.lineno, node.col_offset)
0
         except KeyError:
0
-            if not import_starred and not is_builtin(name):
0
+            if not import_starred and not self.is_builtin(name):
0
                 self.report(messages.UndefinedName, node.lineno, node.col_offset, name)
0
 
0
     def assign_vars(self, targets, report_redef=True):
0
@@ -302,7 +297,7 @@ class Checker(ast.NodeVisitor):
0
         self.pop_scope()
0
 
0
     def visit_excepthandler(self, node):
0
-        if node.name is not None:
0
+        if node.type is not None:
0
             self.visit(node.type)
0
         if node.name is not None:
0
             self.assign_vars(node.name)
0
@@ -370,3 +365,13 @@ class Checker(ast.NodeVisitor):
0
         for node in nodes:
0
             self.visit(node)
0
 
0
+    def is_builtin(self, name):
0
+        if hasattr(__builtin__, name):
0
+            return True
0
+        if name in defined_names:
0
+            return True
0
+        if name in self.builtins:
0
+            return True
0
+
0
+        return False
0
+

Comments