Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Nested classes issue #215

Open
Mahdi-py opened this issue Apr 23, 2021 · 3 comments
Open

Nested classes issue #215

Mahdi-py opened this issue Apr 23, 2021 · 3 comments

Comments

@Mahdi-py
Copy link

Mahdi-py commented Apr 23, 2021

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.

@rubik
Copy link
Owner

rubik commented May 17, 2021

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.

@Vinno97
Copy link

Vinno97 commented Dec 20, 2021

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?

radon/radon/visitors.py

Lines 310 to 314 in 44655c8

body_complexity += (
visitor.complexity
+ visitor.functions_complexity
+ len(visitor.functions)
)

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

@rubik
Copy link
Owner

rubik commented Feb 23, 2022

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants