Coverage for metrics / cyclomatic / python.py: 85%

13 statements  

« prev     ^ index     » next       coverage.py v7.13.3, created at 2026-02-08 15:04 -0800

1"""McCabe cyclomatic complexity for Python.""" 

2 

3from __future__ import annotations 

4 

5from metrics.cyclomatic.shared import ( 

6 create_cyclomatic_computer, 

7 create_cyclomatic_wrapper, 

8) 

9 

10 

11_PY_DECISION_TYPES = { 

12 "if_statement", 

13 "elif_clause", 

14 "for_statement", 

15 "while_statement", 

16 "except_clause", 

17 "conditional_expression", 

18 "case_clause", 

19 "boolean_operator", 

20} 

21 

22 

23def _py_skip_check(child, top_func) -> bool: 

24 """Skip nested function/class definitions.""" 

25 if child.type == "function_definition" and child is not top_func: 

26 return True 

27 if child.type == "class_definition": 

28 return True 

29 if child.type == "decorated_definition": 

30 return True 

31 return False 

32 

33 

34_count_decisions = create_cyclomatic_computer(_py_skip_check, _PY_DECISION_TYPES) 

35compute_cyclomatic_py = create_cyclomatic_wrapper(_count_decisions)