Georg Brandl avatar Georg Brandl committed 515ce28

HACK HACK to get coverage for Python 3 syntax files with print function

Comments (0)

Files changed (2)


     nodeDepth = 0
     traceTree = False
-    def __init__(self, tree, filename='(none)'):
+    def __init__(self, tree, filename='(none)', lnooffset=0):
         self._deferredFunctions = []
         self._deferredAssignments = []
         self.dead_scopes = []
         self.messages = []
         self.filename = filename
+        self.lnooffset = lnooffset
         self.scopeStack = [ModuleScope()]
         self.futuresAllowed = True
         self.noRedef = 0
     def report(self, messageClass, *args, **kwargs):
-        self.messages.append(messageClass(self.filename, *args, **kwargs))
+        msg = messageClass(self.filename, *args, **kwargs)
+        msg.lineno -= self.lnooffset
+        self.messages.append(msg)
     def handleChildren(self, tree):
         for node in iter_child_nodes(tree):


     # First, compile into an AST and handle syntax errors.
-        tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
+        try:
+            tree = compile(codeString, filename, "exec", _ast.PyCF_ONLY_AST)
+            lnooffset = 0
+        except SyntaxError:
+            # HACK: try again with print function
+            tree = compile('from __future__ import print_function\n' +
+                           codeString, filename, "exec", _ast.PyCF_ONLY_AST)
+            lnooffset = 1
     except SyntaxError, value:
         msg = value.args[0]
         return 1
         # Okay, it's syntactically valid.  Now check it.
-        w = checker.Checker(tree, filename)
+        w = checker.Checker(tree, filename, lnooffset)
         w.messages.sort(lambda a, b: cmp(a.lineno, b.lineno))
         for warning in w.messages:
             print warning
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
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.