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

Respect mixed return and raise cases in return-type analysis #9310

Merged
merged 1 commit into from
Dec 29, 2023

Conversation

charliermarsh
Copy link
Member

@charliermarsh charliermarsh commented Dec 29, 2023

Summary

Given:

from somewhere import get_cfg

def lookup_cfg(cfg_description):
    cfg = get_cfg(cfg_description)
    if cfg is not None:
        return cfg
    raise AttributeError(f"No cfg found matching {cfg_description}")

We were analyzing the method from last-to-first statement. So we saw the raise, then assumed the method always raised. In reality, though, it might return. This PR improves the branch analysis to respect these mixed cases.

Closes #9269.
Closes #9304.

@charliermarsh charliermarsh added the bug Something isn't working label Dec 29, 2023
Copy link
Contributor

github-actions bot commented Dec 29, 2023

ruff-ecosystem results

Linter (stable)

✅ ecosystem check detected no linter changes.

Linter (preview)

✅ ecosystem check detected no linter changes.

Formatter (stable)

✅ ecosystem check detected no format changes.

Formatter (preview)

✅ ecosystem check detected no format changes.

@charliermarsh charliermarsh enabled auto-merge (squash) December 29, 2023 16:42
@charliermarsh charliermarsh merged commit 2895e7d into main Dec 29, 2023
16 checks passed
@charliermarsh charliermarsh deleted the charlie/tweak branch December 29, 2023 16:46
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 this pull request may close these issues.

Incorrect ANN201 autofix unsafe ANN autofix seems to ignore return in for loop
1 participant