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

Report on uncatchable exception handlers (?) #349

Open
jakkdl opened this issue Feb 7, 2023 · 3 comments
Open

Report on uncatchable exception handlers (?) #349

jakkdl opened this issue Feb 7, 2023 · 3 comments

Comments

@jakkdl
Copy link
Contributor

jakkdl commented Feb 7, 2023

Was surprised bugbear didn't report this, but not encountered in live code so I don't know if it's seen much / ever in the wild:

try:
  ...
except BaseException:
  ...
except:
  ...

will report B001/E722, but in a project that uses bare excepts widely and disables those checks the except never being possible to run seems like a separate error.

try:
  ...
except BaseException:
  ...
except Exception:
  ...

Gives no warning, nor does a plausibly more common

try:
  ...
except Exception:
  ...
except ValueError:
  ...

or similar variants. Checking whether a caught exception is a built-in, and if so issubclass of a previously caught exception, seems straightforward. I quickly checked mypy and vulture as well and neither of them sees it. But this might definitely not be common enough that it's worth bothering with.

@JelleZijlstra
Copy link
Collaborator

For what it's worth, Pyright/Pylance catches this:

Screen Shot 2023-02-07 at 2 48 55 AM

@jakkdl
Copy link
Contributor Author

jakkdl commented Feb 7, 2023

For what it's worth, Pyright/Pylance catches this:

It does not catch bare except after a BaseException (and since py3 exceptions have to inherit from baseexception), but indeed looks like it catches the other ones.

@cooperlees
Copy link
Collaborator

If nothing catches Exception (and children) being caught/except after BaseException, I think this is worth a check. BaseException catching in general is even more evil than Exception and I generally won't approve PRs that do it ...

I also like it checks all other exceptions too, as not everyone runs VSCode / IDE with this detection.

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

3 participants