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

Python: Mixing implicit/explicit returns false positive #18521

Open
henriquevcosta opened this issue Jan 17, 2025 · 2 comments
Open

Python: Mixing implicit/explicit returns false positive #18521

henriquevcosta opened this issue Jan 17, 2025 · 2 comments

Comments

@henriquevcosta
Copy link

Description of the false positive

I am seeing an Mixing implicit and explicit returns may indicate an error as implicit returns always return None. alert where the code actually always has a return.
In my interpretation of the alert it seems that the issue is that CodeQL isn't considering the case _: in a match to be acting as a default case so it believes that there should be a return None outside of the match.

Code samples or links to source code

I had to slightly redact the code but I believe that this is the same:
(ironically this is in a piece of code that processes codeql alerts, don't get confused 😄)

    def codeql_severity_conversion(self, security_severity, severity):
        match (security_severity, severity):
            case ("critical", _) | ("high", _) | ("low", _):
                return security_severity
            case ("medium", _):
                return "moderate"
            case (None, "error"):
                return "high"
            case (None, "warning"):
                return "moderate"
            case (None, "note") | (None, "none"):
                return "low"
            case _:
                return "high"

URL to the alert on GitHub code scanning (optional)

I'd rather not share the link outside the enterprise. The link to the rule in the alert is https://github.com/github/codeql/blob/d42788844f7ec0a6b9832140313cc2318e513987/python/ql/src/Functions/ConsistentReturns.ql

@redsun82
Copy link
Contributor

Hi @henriquevcosta, thanks for reporting this! We will internally track this, though be aware that fixing false positives is not currently our top priority. That said, this may hide a more general problem in our Python data flow modeling, so we may be still having a look at this.

@henriquevcosta
Copy link
Author

Yup no worries. Thank you for the feedback

@smowton smowton changed the title False positive Python: Mixing implicit/explicit returns false positive Jan 17, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants