Chris Adams  committed de86863

mccabe check: gracefully handle compile failures

compiler.parse() will fail with an unhandled AttributeError when called with a
module. Now a message will be printed to stderr and the mccabe check will return
0 rather than crashing.

  • Participants
  • Parent commits d519e27
  • Branches default

Comments (0)

Files changed (1)

File flake8/

 def get_code_complexity(code, min=7, filename='stdin'):
     complex = []
-    ast = compiler.parse(code)
+    try:
+        ast = compiler.parse(code)
+    except AttributeError as e:
+        print >>sys.stderr, "Unable to parse %s: %s" % (filename, e)
+        return 0
     visitor = PathGraphingAstVisitor()
     visitor.preorder(ast, visitor)
     for graph in visitor.graphs.values():