Fix exception handler parenthesis removal for Python 3.14+#23126
Merged
Conversation
Summary -- Fixes #23125. We were missing handling for starred elements within a tuple of exceptions. This produces valid syntax but changes the AST from a non-starred `except` handler to a starred `except` handler (which can be invalid if there are other non-starred handlers): ```py try: ... except (*exceptions, ValueError): ... try: ... except *exceptions, ValueError: ... ``` Starred expressions in other positions are outright invalid: ```pycon >>> try: ... ... except Exception, *exceptions: ... ... File "<python-input-8>", line 2 except Exception, *exceptions: ... ^ SyntaxError: invalid syntax ``` We now preserve parentheses in these cases as well. Test Plan -- New tests derived from the issue
|
amyreese
approved these changes
Feb 6, 2026
dylwil3
approved these changes
Feb 6, 2026
Collaborator
dylwil3
left a comment
There was a problem hiding this comment.
Looks good, thanks for fixing this!
21 tasks
ichoosetoaccept
added a commit
to detailobsessed/surfmon
that referenced
this pull request
Feb 13, 2026
## Summary Upgrade ruff from 0.15.0 to 0.15.1 and fix the except clause formatting bug that ruff 0.15.1 addresses. ## Problem Ruff 0.15.0 had a bug where it incorrectly removed parentheses from multi-exception `except` clauses on Python 3.14+ (PEP 758). Ruff 0.15.1 fixes this (astral-sh/ruff#23126). ## Solution - Bump ruff to 0.15.1 in pyproject.toml and uv.lock - Update prek.toml hook rev to match ## Changes - `pyproject.toml` — ruff version bump - `prek.toml` — ruff hook rev update - `uv.lock` — lockfile refresh
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
Summary
Fixes #23125. We were missing handling for starred elements within a tuple of
exceptions. This produces valid syntax but changes the AST from a
non-starred
excepthandler to a starredexcepthandler (which can be invalidif there are other non-starred handlers):
Starred expressions in other positions are outright invalid:
We now preserve parentheses in these cases as well.
Test Plan
New tests derived from the issue