radon
radon copied to clipboard
Nested classes issue
class student2:
def nott(self):
if True and False:
return
elif True:
return
else:
return
return self
class classmate:
def example(self):
return 0
@staticmethod
def staticMethod():
return None
the "radon cc {path}.py" does not detect any nested classes. The above example is one of many. Do not bother about the logic of the code I am just experimenting something for other purposes. The program will not detect the nested classes nor the methods of that class.
Thanks for the bug report @Mahdi-py. Indeed, this is due to the way the AST visitor is implemented. I'll take a look at a possible fix in the near future.
I noticed the same issue whilst reading the code itself. Am I right assuming that adding visitor.classes_complexity
to the following sum would fix this?
https://github.com/rubik/radon/blob/44655c8951ffd15b6b31a967914ade311dd7aeb0/radon/visitors.py#L310-L314
Alternatively change
body_complexity += (
visitor.complexity
+ visitor.functions_complexity
+ len(visitor.functions)
)
to
body_complexity += (
visitor.total_complexity
+ len(visitor.functions)
)
and change the off
property of the visitor to True
That fix would allow Radon to count the complexity of all the code within the nested classes. That's the correct thing to do. However, it won't cause the nested classes to be shown in the reports. Since we do not report nested functions, I think that's also consistent with the rest of the code. I'll commit this fix after writing some test cases.