Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
I was working in ruff implementing B030 when I noticed that the test case for the warning didn't look right. It may be that another rule catches this issue, but it made sense to me that B030 would catch it as well.
This code causes an exception,
TypeError: catching classes that do not inherit from BaseException is not allowed
, because the inner tuple isn't expanded out automatically. It passes, however, if those tuples are starred:The wording for B030 makes it sound like this is the exact error it's meant to catch, so I updated the
_flatten_excepthandler
method to be more selective when flattening tuples and arrays. In the updated code, the(RuntimeError, ...)
tuple is returned fully, which then gets it placed in the bad_handlers list.Let me know if there's anything I missed, any improvements I can make, or if I should have started this convo in an issue. I had already gotten this logic working in Rust, so I tried to port it into python and plug it in to see if I could get the same result. Work was already done, so I figured a PR was a decent way to present it.