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

Document try complexity computation #20

Closed
HarrySky opened this issue Jul 22, 2021 · 1 comment · Fixed by #22
Closed

Document try complexity computation #20

HarrySky opened this issue Jul 22, 2021 · 1 comment · Fixed by #22

Comments

@HarrySky
Copy link

Hi, thanks for this great tool 😄 I was scratching my head when adding/removing any lines from try block was influencing cognitive complexity and searched in your documentation and then code why is that and found this line in code:

# add +1 for all try nodes except body

It means that any line added inside try block will increment complexity (code below gives complexity 4)

def a(b, c):
    try:
        print(1)
        print(2)
        print(3)
        print(4)
    except Exception:
        raise

This behavior is unexpected as it was not mentioned in SonarSource links provided, can we document it here or in flake8 extension? Thanks

@AndersSteenNilsen
Copy link

This is not a documentation fault but a bug.
I think I fixed the issue.

def a(b, c):
    try:
        print(1)
        print(2)
        print(3)
        print(4)
    except Exception:  # +1 (nesting 0)
        raise                  # +0 (nesting 1)

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

Successfully merging a pull request may close this issue.

2 participants