Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_mccabe_violations_for_file(filepath, max_complexity):
code = _read(filepath)
tree = compile(code, filepath, "exec", ast.PyCF_ONLY_AST)
visitor = PathGraphingAstVisitor()
visitor.preorder(tree, visitor)
violations = []
for graph in visitor.graphs.values():
if graph.complexity() >= max_complexity:
complex_function_name = graph.entity
if complex_function_name.startswith('If '):
complex_function_name = 'if __name__ == "__main__"'
violations.append(complex_function_name)
return violations