mirror of
https://github.com/PyCQA/flake8.git
synced 2026-04-04 04:06:54 +00:00
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.
This commit is contained in:
parent
a470004706
commit
b56abdedf3
1 changed files with 6 additions and 1 deletions
|
|
@ -172,7 +172,12 @@ class PathGraphingAstVisitor(compiler.visitor.ASTVisitor):
|
|||
|
||||
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():
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue