Skip to content

fix: suppress SIM105 for except* (fixes #23798)#24139

Closed
r266-tech wants to merge 1 commit intoastral-sh:mainfrom
r266-tech:fix-sim105-except-star
Closed

fix: suppress SIM105 for except* (fixes #23798)#24139
r266-tech wants to merge 1 commit intoastral-sh:mainfrom
r266-tech:fix-sim105-except-star

Conversation

@r266-tech
Copy link
Copy Markdown

Summary

Fixes #23798.

SIM105 suggests replacing except* ...: pass with contextlib.suppress(), but contextlib.suppress only gained support for BaseExceptionGroup in Python 3.12. This means the suggested fix is incorrect for Python 3.11 when using except* syntax.

Changes

  • Added is_star parameter to suppressible_exception() function
  • When the try statement uses except*, skip the SIM105 rule entirely
  • Added test fixture SIM105_5.py to verify except* cases are not flagged

Rationale

As described in the issue, except* handles BaseExceptionGroup, and contextlib.suppress did not support exception groups until Python 3.12. Even when targeting Python 3.12+, the semantic equivalence is not guaranteed, so it's safest to suppress SIM105 for all except* cases.

SIM105 suggested replacing 'except* ...: pass' with contextlib.suppress(),
but contextlib.suppress doesn't support BaseExceptionGroup until Python 3.12.
This fix ensures SIM105 is not triggered when using except* syntax.
@ntBre
Copy link
Copy Markdown
Contributor

ntBre commented Mar 23, 2026

Thanks, but there's already an open PR for this issue: #23869

@ntBre ntBre closed this Mar 23, 2026
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 this pull request may close these issues.

SIM105 should be suppressed for except* in Python 3.11

4 participants