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

TRY002 does not take into account BaseException #12612

Closed
epenet opened this issue Aug 1, 2024 · 1 comment · Fixed by #12620
Closed

TRY002 does not take into account BaseException #12612

epenet opened this issue Aug 1, 2024 · 1 comment · Fixed by #12620

Comments

@epenet
Copy link
Contributor

epenet commented Aug 1, 2024

Spotted in home-assistant/core#123021

It seems that pylint doesn't like Exception nor BaseException
https://pylint.pycqa.org/en/latest/user_guide/messages/warning/broad-exception-raised.html

But ruff is quite happy to let BaseException pass

I think both should trigger a warning, same as regular Exception

It should be an easy fix in

if checker.semantic().match_builtin_expr(node, "Exception") {

@epenet epenet changed the title TRY002 does not take into account BaseException TRY002 does not take into account BaseException Aug 1, 2024
@dylwil3
Copy link
Collaborator

dylwil3 commented Aug 1, 2024

I think Ruff is correctly reproducing the rule from tryceratops, which is implemented here.

The pylint rule --overgeneral-exceptions used to coincide with this rule but has since changed in two ways:

  • The rule is now configurable, so the user can specify which exceptions are too general.
  • The default configuration includes BaseException.

So I think this needs a decision from the maintainers. Should we:

  1. Add BaseException to the TRY002 violation and call it a day (this would disagree with tryceratops).
  2. Create a new rule in Pylint (not sure how to find the code) where Exception and BaseException both give violations.
  3. Same as (2) but make it configurable as in Pylint.
  4. Same as (3) and then also remove/redirect TRY0002.
  5. Something else.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants