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

Consider extending suppressible-exception (SIM105) to multi-line try blocks #8593

Open
DetachHead opened this issue Nov 10, 2023 · 3 comments
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule

Comments

@DetachHead
Copy link

try: # error
    ...
except Exception:
    pass

try: # no error
    ...
    ...
except Exception:
    pass

playground

@KotlinIsland
Copy link
Contributor

I think this is intentional, although I don't really see why.

@konstin
Copy link
Member

konstin commented Nov 10, 2023

For context, this is due to #1947/#1948 and flake8-simplify doing the same (https://github.com/MartinThoma/flake8-simplify/blob/60e0ddbc82973af673259850cc00c6e8221f8643/flake8_simplify/rules/ast_try.py#L46). I'm not sure if that's the best way to handle this though

@charliermarsh
Copy link
Member

I think the current restriction is not unreasonable, but I'd be open to reviewing a PR that modifies the rule to use the more limited exemption from #1947:

If a try: block has an unreachable end because all its non-exceptional control flow paths end with a return, raise, break, or continue, should we exempt it from SIM105?

Though it'd be contingent on reviewing the changes in the ecosystem checks.

@charliermarsh charliermarsh added the rule Implementing or modifying a lint rule label Nov 11, 2023
@charliermarsh charliermarsh changed the title suppressible-exception (SIM105) false negative when multiple lines in try block Consider extending suppressible-exception (SIM105) to multi-line try blocks Nov 11, 2023
@charliermarsh charliermarsh added the needs-decision Awaiting a decision from a maintainer label Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs-decision Awaiting a decision from a maintainer rule Implementing or modifying a lint rule
Projects
None yet
Development

No branches or pull requests

4 participants