Skip to content

Commit

Permalink
fix(visitor): do not undercount a class' complexity
Browse files Browse the repository at this point in the history
Fixes #156.
  • Loading branch information
rubik committed Jan 26, 2019
1 parent 4c95e0a commit 1981e2e
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 6 deletions.
6 changes: 3 additions & 3 deletions radon/tests/test_complexity_visitor.py
Expand Up @@ -356,7 +356,7 @@ def n(self, k):
while self.m(k) < k:
k -= self.m(k ** 2 - min(self.m(j) for j in range(k ** 4)))
return k
''', (6, 4, 3)),
''', (8, 4, 3)),

('''
class B(object):
Expand All @@ -377,7 +377,7 @@ def test(self, func):
elif a > self.ATTR ** 2:
yield self.__iter__()
yield iter(a)
''', (5, 1, 3)),
''', (7, 1, 3)),
]


Expand Down Expand Up @@ -435,7 +435,7 @@ def inner(n):
if a < b:
b, a = a, inner(b)
return a, b
''', (3, 1, 2, 6)),
''', (3, 1, 3, 7)),

('''
class f(object):
Expand Down
4 changes: 2 additions & 2 deletions radon/tests/test_other_metrics.py
Expand Up @@ -115,10 +115,10 @@ def m(self, j):
# CC = 4
# LLOC = 9
# CM % = 38.46153846153847
(second_mi, 94.10928035154717, True),
(second_mi, 93.84027450359395, True),

# CM % = 15.384615384615385
(second_mi, 89.11076918364455, False),
(second_mi, 88.84176333569131, False),
]


Expand Down
3 changes: 2 additions & 1 deletion radon/visitors.py
Expand Up @@ -272,7 +272,8 @@ def visit_ClassDef(self, node):
visitor.visit(child)
methods.extend(visitor.functions)
body_complexity += (visitor.complexity +
visitor.functions_complexity)
visitor.functions_complexity +
len(visitor.functions))
visitors_max_lines.append(visitor.max_line)
inner_classes.extend(visitor.classes)

Expand Down

0 comments on commit 1981e2e

Please sign in to comment.