Skip to content

SIM105 should be suppressed for except* in Python 3.11 #23798

@dscorbett

Description

@dscorbett

Summary

The fix for suppressible-exception (SIM105) can change the program’s behavior in Python 3.11 for except*. If some code uses except*, it’s probably because a BaseExceptionGroup can be raised. Because contextlib.suppress only gained support for BaseExceptionGroup in Python 3.12, the fix is most likely wrong for except* in Python 3.11. SIM105 should be suppressed in that case: not just the fix, but the whole rule, because there’s generally no way to simplify the code under these circumstances, so it’s not helpful for Ruff to flag it at all. Example:

$ cat >sim105.py <<'# EOF'
def raise_group(x):
    raise ExceptionGroup("!", [ValueError(x)])
try:
   raise_group(1)
except* ValueError:
   pass
# EOF

$ python3.11 sim105.py; echo $?
0

$ ruff --isolated check --select SIM105 sim105.py --unsafe-fixes --fix --target-version py311
Found 1 error (1 fixed, 0 remaining).

$ cat sim105.py
import contextlib
def raise_group(x):
    raise ExceptionGroup("!", [ValueError(x)])
with contextlib.suppress(ValueError):
   raise_group(1)

$ python3.11 sim105.py 2>&1 | sed 's:/.*/::g'
  + Exception Group Traceback (most recent call last):
  |   File "sim105.py", line 5, in <module>
  |     raise_group(1)
  |   File "sim105.py", line 3, in raise_group
  |     raise ExceptionGroup("!", [ValueError(x)])
  | ExceptionGroup: ! (1 sub-exception)
  +-+---------------- 1 ----------------
    | ValueError: 1
    +------------------------------------

Version

ruff 0.15.5 (5e4a3d9 2026-03-05)

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingruleImplementing or modifying a lint rule

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions