[flake8-bugbear] Allow tuples of exceptions (B030)#10437
[flake8-bugbear] Allow tuples of exceptions (B030)#10437charliermarsh merged 11 commits intoastral-sh:mainfrom
flake8-bugbear] Allow tuples of exceptions (B030)#10437Conversation
|
|
Oh, we seem to have worked on it at the same time, I just wanted to open a PR fixing this as well 😅 I checked out your PR and checked it against my tests, and it doesn't seem to be complete with the nesting. try:
...
except (ValueError, *(RuntimeError, TypeError), *((ArithmeticError,) + (EOFError,))):
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ B030
...This is flagged as error, although this is valid. |
|
Ok I can close this in favor of yours. |
|
@autinerd actually let me know if you think I should fix that bug and continue, or just close this! Sorry about the confusion - I meant to say that I'd work on this issue. |
|
I think that would be a good idea if you work on it, as my knowledge in the Ruff codebase (and Rust in general) is not really good. My solution was to handle it recursively, maybe it is possible to do it iteratively as well. |
| try: | ||
| pass | ||
| except (ValueError, *(RuntimeError, TypeError), *((ArithmeticError,) + (EOFError,))): | ||
| pass |
charliermarsh
left a comment
There was a problem hiding this comment.
This looks good! Thanks.
| Expr::BinOp(ast::ExprBinOp { | ||
| left, | ||
| right, | ||
| op: Operator::Add, |
There was a problem hiding this comment.
Gated these to Operator::Add.
flake8-bugbear] Allow tuples of exceptions (B030)
|
No need for preview here since it's a bug fix. |
Fixes #10426
Summary
Fix rule B030 giving a false positive with Tuple operations like
+.Playground
Reviewer notes
This is a little more convoluted than I was expecting -- because we can have valid nested Tuples with operations done on them, the flattening logic has become a bit more complex.
Shall I guard this behind --preview?
Test Plan
Unit tested.