Updated to pyflakes 1.0.0.

Tue, 20 Oct 2015 19:19:12 +0200

author
Detlev Offenbach <detlev@die-offenbachs.de>
date
Tue, 20 Oct 2015 19:19:12 +0200
changeset 4502
76f2b46437a6
parent 4501
3224f20d8eb0
child 4503
d68dcbe1deb3

Updated to pyflakes 1.0.0.

Plugins/CheckerPlugins/SyntaxChecker/pyflakes/__init__.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/SyntaxChecker/pyflakes/checker.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/SyntaxChecker/pyflakes/messages.py file | annotate | diff | comparison | revisions
Plugins/CheckerPlugins/SyntaxChecker/pyflakes/translations.py file | annotate | diff | comparison | revisions
--- a/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/__init__.py	Tue Oct 20 19:14:55 2015 +0200
+++ b/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/__init__.py	Tue Oct 20 19:19:12 2015 +0200
@@ -32,6 +32,23 @@
 """
 
 """ Changes
+0.9.2 (2015-06-17):
+  - Fix a traceback when a global is defined in one scope, and used in another.
+
+0.9.1 (2015-06-09):
+  - Update NEWS.txt to include 0.9.0, which had been forgotten.
+
+0.9.0 (2015-05-31):
+  - Exit gracefully, not with a traceback, on SIGINT and SIGPIPE.
+  - Fix incorrect report of undefined name when using lambda expressions in
+    generator expressions.
+  - Don't crash on DOS line endings on Windows and Python 2.6.
+  - Don't report an undefined name if the 'del' which caused a name to become
+    undefined is only conditionally executed.
+  - Properly handle differences in list comprehension scope in Python 3.
+  - Improve handling of edge cases around 'global' defined variables.
+  - Report an error for 'return' outside a function.
+
 0.8.1 (2014-03-30):
   - Detect the declared encoding in Python 3.
   - Do not report redefinition of import in a local scope, if the
@@ -149,4 +166,4 @@
   - Improve reporting of unbound locals
 """
 
-__version__ = '0.8.1'
+__version__ = '1.0.0'
--- a/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/checker.py	Tue Oct 20 19:14:55 2015 +0200
+++ b/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/checker.py	Tue Oct 20 19:19:12 2015 +0200
@@ -455,6 +455,10 @@
             elif isinstance(existing, Importation) and value.redefines(existing):
                 existing.redefined.append(node)
 
+        if value.name in self.scope:
+            # then assume the rebound name is used as a global or within a loop
+            value.used = self.scope[value.name].used
+
         self.scope[value.name] = value
 
     def getNodeHandler(self, node_class):
@@ -478,7 +482,7 @@
             return
 
         scopes = [scope for scope in self.scopeStack[:-1]
-                  if isinstance(scope, (FunctionScope, ModuleScope))]
+                  if isinstance(scope, (FunctionScope, ModuleScope, GeneratorScope))]
         if isinstance(self.scope, GeneratorScope) and scopes[-1] != self.scopeStack[-2]:
             scopes.append(self.scopeStack[-2])
 
@@ -533,14 +537,30 @@
             binding = ExportBinding(name, node.parent, self.scope)
         else:
             binding = Assignment(name, node)
-        if name in self.scope:
-            binding.used = self.scope[name].used
         self.addBinding(node, binding)
 
     def handleNodeDelete(self, node):
+
+        def on_conditional_branch():
+            """
+            Return `True` if node is part of a conditional body.
+            """
+            current = getattr(node, 'parent', None)
+            while current:
+                if isinstance(current, (ast.If, ast.While, ast.IfExp)):
+                    return True
+                current = getattr(current, 'parent', None)
+            return False
+
         name = getNodeName(node)
         if not name:
             return
+
+        if on_conditional_branch():
+            # We can not predict if this conditional branch is going to
+            # be executed.
+            return
+
         if isinstance(self.scope, FunctionScope) and name in self.scope.globals:
             self.scope.globals.remove(name)
         else:
@@ -638,8 +658,8 @@
 
     # "stmt" type nodes
     DELETE = PRINT = FOR = ASYNCFOR = WHILE = IF = WITH = WITHITEM = \
-        ASYNCWITH = RAISE = TRYFINALLY = ASSERT = EXEC = EXPR = \
-        ASSIGN = handleChildren
+        ASYNCWITH = ASYNCWITHITEM = RAISE = TRYFINALLY = ASSERT = EXEC = \
+        EXPR = ASSIGN = handleChildren
 
     CONTINUE = BREAK = PASS = ignore
 
@@ -662,14 +682,38 @@
         EQ = NOTEQ = LT = LTE = GT = GTE = IS = ISNOT = IN = NOTIN = ignore
 
     # additional node types
-    LISTCOMP = COMPREHENSION = KEYWORD = handleChildren
+    COMPREHENSION = KEYWORD = handleChildren
 
     def GLOBAL(self, node):
         """
         Keep track of globals declarations.
         """
-        if isinstance(self.scope, FunctionScope):
-            self.scope.globals.update(node.names)
+        # In doctests, the global scope is an anonymous function at index 1.
+        global_scope_index = 0#1 if self.withDoctest else 0
+        global_scope = self.scopeStack[global_scope_index]
+
+        # Ignore 'global' statement in global scope.
+        if self.scope is not global_scope:
+
+            # One 'global' statement can bind multiple (comma-delimited) names.
+            for node_name in node.names:
+                node_value = Assignment(node_name, node)
+
+                # Remove UndefinedName messages already reported for this name.
+                self.messages = [
+                    m for m in self.messages if not
+                    isinstance(m, messages.UndefinedName) and not
+                    m.message_args[0] == node_name]
+
+                # Bind name to global scope if it doesn't exist already.
+                global_scope.setdefault(node_name, node_value)
+
+                # Bind name to non-global scopes, but as already "used".
+                node_value.used = (global_scope, node)
+                for scope in self.scopeStack[global_scope_index + 1:]:
+                    scope[node_name] = node_value
+                    if isinstance(scope, FunctionScope):
+                        scope.globals.add(node_name)
 
     NONLOCAL = GLOBAL
 
@@ -678,6 +722,8 @@
         self.handleChildren(node)
         self.popScope()
 
+    LISTCOMP = handleChildren if PY2 else GENERATOREXP
+
     DICTCOMP = SETCOMP = GENERATOREXP
 
     def NAME(self, node):
@@ -701,6 +747,10 @@
             raise RuntimeError("Got impossible expression context: %r" % (node.ctx,))
 
     def RETURN(self, node):
+        if isinstance(self.scope, ClassScope):
+            self.report(messages.ReturnOutsideFunction, node)
+            return
+
         if (
             node.value and
             hasattr(self.scope, 'returnValue') and
@@ -713,7 +763,7 @@
         self.scope.isGenerator = True
         self.handleNode(node.value, node)
 
-    YIELDFROM = YIELD
+    AWAIT = YIELDFROM = YIELD
 
     def FUNCTIONDEF(self, node):
         for deco in node.decorator_list:
--- a/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/messages.py	Tue Oct 20 19:14:55 2015 +0200
+++ b/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/messages.py	Tue Oct 20 19:19:12 2015 +0200
@@ -248,26 +248,6 @@
         self.message_args = (name,)
 
 
-class Redefined(Message):
-    """
-    Class defining the "Redefined" message.
-    """
-    message_id = 'F09'
-    message = 'redefinition of %r from line %r'
-
-    def __init__(self, filename, loc, name, orig_loc):
-        """
-        Constructor
-        
-        @param filename name of the file (string)
-        @param loc location of the issue
-        @param name name of the redefined function (string)
-        @param orig_loc location of the original definition
-        """
-        Message.__init__(self, filename, loc)
-        self.message_args = (name, orig_loc.lineno)
-
-
 class LateFutureImport(Message):
     """
     Class defining the "Late Future Import" message.
@@ -317,3 +297,13 @@
     """
     message_id = 'F14'
     message = '\'return\' with argument inside generator'
+
+
+class ReturnOutsideFunction(Message):
+    """
+    Class defining the "Return outside function" message.
+    
+    Indicates a return statement outside of a function/method.
+    """
+    message_id = 'F15'
+    message = '\'return\' outside function'
--- a/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/translations.py	Tue Oct 20 19:14:55 2015 +0200
+++ b/Plugins/CheckerPlugins/SyntaxChecker/pyflakes/translations.py	Tue Oct 20 19:19:12 2015 +0200
@@ -57,6 +57,9 @@
     'F14': QCoreApplication.translate(
         'pyFlakes',
         "'return' with argument inside generator"),
+    'F15': QCoreApplication.translate(
+        'pyFlakes',
+        "'return' outside function"),
 }
 
 

eric ide

mercurial