Handle case when there are not complexities available
@@ -531,6 +531,7 @@ class ModuleTestCluster:
cyclomatic_complexity = self.__compute_cyclomatic_complexities(
self.function_data_for_accessibles.values()
)
+ if cyclomatic_complexity is not None:
tracking_fun(RuntimeVariable.McCabeMin, cyclomatic_complexity.min)
tracking_fun(RuntimeVariable.McCabeMean, cyclomatic_complexity.mean)
tracking_fun(RuntimeVariable.McCabeMedian, cyclomatic_complexity.median)
@@ -542,7 +543,7 @@ class ModuleTestCluster:
@staticmethod
def __compute_cyclomatic_complexities(
callable_data: typing.Iterable[_CallableData],
- ) -> CyclomaticComplexity:
+ ) -> CyclomaticComplexity | None:
# Collect complexities only for callables that had an AST. Their minimal
# complexity is 1, the value None symbolises a callable that had no AST present,
# either because there is none or because it is an implicitly added function,
@@ -552,6 +553,8 @@ class ModuleTestCluster:
for item in callable_data
if item.cyclomatic_complexity is not None
]
+ if len(complexities) == 0:
+ return None
return ModuleTestCluster.CyclomaticComplexity(
min=min(complexities),
mean=mean(complexities),
