MCPcopy Create free account
hub / github.com/PyCQA/mccabe / get_code_complexity

Function get_code_complexity

mccabe.py:273–289  ·  view source on GitHub ↗
(code, threshold=7, filename='stdin')

Source from the content-addressed store, hash-verified

271
272
273def get_code_complexity(code, threshold=7, filename='stdin'):
274 try:
275 tree = compile(code, filename, "exec", ast.PyCF_ONLY_AST)
276 except SyntaxError:
277 e = sys.exc_info()[1]
278 sys.stderr.write("Unable to parse %s: %s\n" % (filename, e))
279 return 0
280
281 complx = []
282 McCabeChecker.max_complexity = threshold
283 for lineno, offset, text, check in McCabeChecker(tree, filename).run():
284 complx.append('%s:%d:1: %s' % (filename, lineno, text))
285
286 if len(complx) == 0:
287 return 0
288 print('\n'.join(complx))
289 return len(complx)
290
291
292def get_module_complexity(module_path, threshold=7):

Callers 4

get_complexity_numberFunction · 0.90
test_print_messageMethod · 0.90
get_module_complexityFunction · 0.85

Calls 2

McCabeCheckerClass · 0.85
runMethod · 0.80

Tested by 3

get_complexity_numberFunction · 0.72
test_print_messageMethod · 0.72

Used in the wild real call sites across dependent graphs

searching dependent graphs…