Georg Brandl avatar Georg Brandl committed 166a6af

Address review comments from Jp.

Comments (0)

Files changed (2)

pyflakes/checker.py

             self.handleNode(node, tree)
 
     def isDocstring(self, node):
+        """
+        Determine if the given node is a docstring, as long as it is at the
+        correct place in the node tree.
+        """
         return isinstance(node, _ast.Str) or \
                (isinstance(node, _ast.Expr) and
                 isinstance(node.value, _ast.Str))
     RETURN = DELETE = PRINT = WHILE = IF = WITH = RAISE = TRYEXCEPT = \
         TRYFINALLY = ASSERT = EXEC = EXPR = handleChildren
 
-    # XXX continue and break untested
     CONTINUE = BREAK = PASS = ignore
 
-    # "expr" type nodes. XXX lambda and set untested.
+    # "expr" type nodes
     BOOLOP = BINOP = UNARYOP = LAMBDA = IFEXP = DICT = SET = YIELD = COMPARE = \
     CALL = REPR = ATTRIBUTE = SUBSCRIPT = LIST = TUPLE = handleChildren
 
-    # XXX ellipsis untested
     NUM = STR = ELLIPSIS = ignore
 
-    # "slice" type nodes. XXX extslice untested.
+    # "slice" type nodes
     SLICE = EXTSLICE = INDEX = handleChildren
 
     # expression contexts are node instances too, though being constants
-    # XXX del, augload, augstore, param untested.
     LOAD = STORE = DEL = AUGLOAD = AUGSTORE = PARAM = ignore
 
     # same for operators
-    # XXX NOTEQ, LT, LTE, GTE, IS, ISNOT, IN, NOTIN untested
     AND = OR = ADD = SUB = MULT = DIV = MOD = POW = LSHIFT = RSHIFT = \
     BITOR = BITXOR = BITAND = FLOORDIV = INVERT = NOT = UADD = USUB = \
     EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore
 
     # additional node types
-    # XXX ARGUMENTS untested
-    COMPREHENSION = EXCEPTHANDLER = ARGUMENTS = KEYWORD = handleChildren
+    COMPREHENSION = EXCEPTHANDLER = KEYWORD = handleChildren
 
     def addBinding(self, lineno, value, reportRedef=True):
         '''Called when a binding is altered.
             self.handleNode(gen, node)
         self.handleNode(node.elt, node)
 
-    # XXX SETCOMP untested
     GENERATOREXP = SETCOMP = LISTCOMP
 
     # 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 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):
         """
         self.handleChildren(node)
 
     def NAME(self, node):
+        """
+        Handle occurrence of Name (which can be a load/store/delete access.)
+        """
         context = node.ctx.__class__.__name__
         # Locate the name in locals / function / globals scopes.
         if context in ('Load', 'AugLoad'):
                           (_ast.For, _ast.comprehension, _ast.Tuple, _ast.List)):
                 binding = Binding(node.id, node)
             elif (node.id == '__all__' and
-                  isinstance(self.scope, ModuleScope) and
-                  isinstance(node.parent, _ast.Assign)):
+                  isinstance(self.scope, ModuleScope)):
                 binding = ExportBinding(node.id, node.parent.value)
             else:
                 binding = Assignment(node.id, node)

pyflakes/test/test_other.py

         ''')
 
 
+    def test_additionalSyntax(self):
+        """
+        Exercise all syntax not otherwise explicitly tested.
+        """
+        self.flakes('''
+        def f(x):
+            a = x[..., ...]
+            for b in a:
+                break
+                continue
+            return a != b, a < b, a <= b, a >= b, a is b, a is not b, \
+                   a in b, a not in b
+        g = lambda x, y: x + y
+        ''')
+
+
 
 class TestUnusedAssignment(harness.Test):
     """
         with bar as bar:
             pass
         ''', m.UndefinedName)
+
+
+
+class Python27Test(harness.Test):
+    """
+    Tests for checking of syntax only available in Python 2.7 and newer.
+    """
+    if version_info < (2, 7):
+        skip = "Python 2.7 required for dict/set comprehension tests"
+
+    def test_dictComprehension(self):
+        """
+        Dict comprehensions are properly handled.
+        """
+        self.flakes('''
+        a = {1: x for x in range(10)}
+        ''')
+
+    def test_setComprehensionAndLiteral(self):
+        """
+        Set comprehensions are properly handled.
+        """
+        self.flakes('''
+        a = {1, 2, 3}
+        b = {x for x in range(10)}
+        ''')
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.