Georg Brandl avatar Georg Brandl committed 43d2795

Address comments from patch review.

Comments (0)

Files changed (4)

pyflakes/checker.py

     and all items of fields that are lists of nodes.
     """
     for name in node._fields:
-        try:
-            field = getattr(node, name)
-        except AttributeError:
-            continue
+        field = getattr(node, name, None)
         if isinstance(field, astcls):
             yield field
         elif isinstance(field, list):
 
     GENERATOREXP = SETCOMP = LISTCOMP
 
-    def DICTCOMP(self, node):
-        for gen in node.generators:
-            self.handleNode(gen, node)
-        self.handleNode(node.key, node)
-        self.handleNode(node.value, node)
+    # dictionary comprehensions; introduced in Python 2.7
+    #def DICTCOMP(self, node):
+    #    for gen in node.generators:
+    #        self.handleNode(gen, node)
+    #    self.handleNode(node.key, node)
+    #    self.handleNode(node.value, node)
 
     def FOR(self, node):
         """

pyflakes/scripts/pyflakes.py

 
 import sys
 import os
+import _ast
 
 checker = __import__('pyflakes.checker').checker
 
     @return: The number of warnings emitted.
     @rtype: C{int}
     """
-    # Since compiler.parse does not reliably report syntax errors, use the
-    # built in compiler first to detect those.
+    # First, compile into an AST and handle syntax errors.
     try:
-        try:
-            compile(codeString, filename, "exec")
-        except MemoryError:
-            # Python 2.4 will raise MemoryError if the source can't be
-            # decoded.
-            if sys.version_info[:2] == (2, 4):
-                raise SyntaxError(None)
-            raise
-    except (SyntaxError, IndentationError), value:
+        tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
+    except SyntaxError, value:
         msg = value.args[0]
 
         (lineno, offset, text) = value.lineno, value.offset, value.text
 
         return 1
     else:
-        # Okay, it's syntactically valid.  Now parse it into an ast and check
-        # it.
-        # 0x400 is the compile flag PyCF_ONLY_AST
-        tree = compile(codeString, filename, "exec", 0x400)
+        # Okay, it's syntactically valid.  Now check it.
         w = checker.Checker(tree, filename)
         w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
         for warning in w.messages:

pyflakes/test/harness.py

 
 import textwrap
+import _ast
 
 from twisted.trial import unittest
 
 class Test(unittest.TestCase):
 
     def flakes(self, input, *expectedOutputs, **kw):
-        # 0x400 is the compile flag PyCF_ONLY_AST
-        ast = compile(textwrap.dedent(input), "<test>", "exec", 0x400)
+        ast = compile(textwrap.dedent(input), "<test>", "exec",
+                      _ast.PyCF_ONLY_AST)
         w = checker.Checker(ast, **kw)
         outputs = [type(o) for o in w.messages]
         expectedOutputs = list(expectedOutputs)

pyflakes/test/test_undefined_names.py

         f()
         ''', m.UndefinedName)
 
-
-
-class Python24Test(harness.Test):
-    """
-    Tests for checking of syntax which is valid in Python 2.4 and newer.
-    """
-    if version_info < (2, 4):
-        skip = "Python 2.4 required for generator expression tests."
+    def test_definedAsStarArgs(self):
+        '''star and double-star arg names are defined'''
+        self.flakes('''
+        def f(a, *b, **c):
+            print a, b, c
+        ''')
 
     def test_definedInGenExp(self):
         """
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.