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

Ruff and Flake8's McCabe complexity differs #3347

Closed
charliermarsh opened this issue Mar 4, 2023 · 7 comments · Fixed by #3519
Closed

Ruff and Flake8's McCabe complexity differs #3347

charliermarsh opened this issue Mar 4, 2023 · 7 comments · Fixed by #3519
Labels
bug Something isn't working

Comments

@charliermarsh
Copy link
Member

From Discord: https://gitlab.com/ppentchev/temp-20230302-ruff-complexity

@charliermarsh charliermarsh added the bug Something isn't working label Mar 4, 2023
@charliermarsh
Copy link
Member Author

Reproduced.

@charliermarsh
Copy link
Member Author

charliermarsh commented Mar 4, 2023

Here's a more minimal repro -- Ruff calls this 3, Flake8 calls this 2:

def process_detect_lines():
    try:
        pass
    finally:
        if res:
            errors.append(f"Non-zero exit code {res}")

I may have to actually learn how this works, because I thought that would've been 3.

@charliermarsh
Copy link
Member Author

I guess it makes sense that it's 2 if you say that the finally has to trigger, but then why is this 2 also?

def process_detect_lines():
    try:
        pass
    finally:
        pass

@JonathanPlasse
Copy link
Contributor

Maybe this is a bug in flake8.

@ashwinrajeev
Copy link

I guess it makes sense that it's 2 if you say that the finally has to trigger, but then why is this 2 also?

def process_detect_lines():
    try:
        pass
    finally:
        pass

I think this is a bug in flake8. This is supposed to be 1, not 2. Radon give this code 1 cc.

https://radon.readthedocs.io/en/latest/intro.html#cyclomatic-complexity

@charliermarsh
Copy link
Member Author

Oh cool, I'll take another look at our implementation with those guidelines in mind.

@akx
Copy link
Contributor

akx commented Mar 10, 2023

I also noticed this when adding Ruff to HA – didn't think to report it back then though! https://github.com/home-assistant/core/blob/fde205c158b704683650cec1d5832ca0858bbd21/pyproject.toml#L293-L302

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants