Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# OK: `except*` should not trigger SIM105 because `contextlib.suppress` doesn't
# support `BaseExceptionGroup` until Python 3.12, so the fix would be incorrect
# for Python 3.11. See https://github.com/astral-sh/ruff/issues/23798


def foo():
pass


try:
foo()
except* ValueError:
pass


try:
foo()
except* (ValueError, OSError):
pass
4 changes: 2 additions & 2 deletions crates/ruff_linter/src/checkers/ast/analyze/statement.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1316,7 +1316,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
handlers,
orelse,
finalbody,
..
is_star,
},
) => {
if checker.is_rule_enabled(Rule::TooManyNestedBlocks) {
Expand Down Expand Up @@ -1355,7 +1355,7 @@ pub(crate) fn statement(stmt: &Stmt, checker: &mut Checker) {
}
if checker.is_rule_enabled(Rule::SuppressibleException) {
flake8_simplify::rules::suppressible_exception(
checker, stmt, body, handlers, orelse, finalbody,
checker, stmt, body, handlers, orelse, finalbody, *is_star,
);
}
if checker.is_rule_enabled(Rule::ReturnInTryExceptFinally) {
Expand Down
1 change: 1 addition & 0 deletions crates/ruff_linter/src/rules/flake8_simplify/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ mod tests {
#[test_case(Rule::SuppressibleException, Path::new("SIM105_2.py"))]
#[test_case(Rule::SuppressibleException, Path::new("SIM105_3.py"))]
#[test_case(Rule::SuppressibleException, Path::new("SIM105_4.py"))]
#[test_case(Rule::SuppressibleException, Path::new("SIM105_5.py"))]
#[test_case(Rule::ReturnInTryExceptFinally, Path::new("SIM107.py"))]
#[test_case(Rule::IfElseBlockInsteadOfIfExp, Path::new("SIM108.py"))]
#[test_case(Rule::CompareWithTuple, Path::new("SIM109.py"))]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -87,7 +87,11 @@ pub(crate) fn suppressible_exception(
handlers: &[ExceptHandler],
orelse: &[Stmt],
finalbody: &[Stmt],
is_star: bool,
) {
if is_star {
return;
}
if !matches!(
try_body,
[Stmt::Delete(_)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
---
source: crates/ruff_linter/src/rules/flake8_simplify/mod.rs
---