Skip to content

Support Python 3.14 unparenthesized exception lists - #1326

Open
Mola-maker wants to merge 1 commit into
google:mainfrom
Mola-maker:fix/pep-758-exception-lists
Open

Mola-maker wants to merge 1 commit into
google:mainfrom
Mola-maker:fix/pep-758-exception-lists

Conversation

@Mola-maker

Copy link
Copy Markdown

Fixes #1319.

YAPF rejects Python 3.14 exception lists such as except ZeroDivisionError, ValueError, IndexError: because its vendored grammar permits at most one comma. Accept arbitrary unparenthesized exception lists, including trailing commas, for both except and except*, while keeping the as alternative limited to a single expression.

Keep a trailing exception-list comma adjacent to the clause's colon without changing existing slice spacing. Regression tests cover formatting and idempotence, long lists, trailing commas, existing parenthesized handlers, and rejection of unparenthesized lists with as.

Validation:

  • python -m pytest -q: 615 passed on Python 3.8.20, 3.12.14, and 3.14.4 (Linux).
  • Confirmed 10 new formatting subcases fail on the original code; the original suite has 611 passing tests.
  • On Python 3.14, 12 additional cases preserve the AST, compile successfully, and remain unchanged on repeated formatting; the issue's reproducer also passes through the CLI.
  • YAPF formatting, flake8 7.1.1, isort 6.0.0, and git diff --check pass for the changed files.

Prepared with Codex assistance.

@google-cla

google-cla Bot commented Sep 29, 2026

Copy link
Copy Markdown

Thanks for your pull request! It looks like this may be your first contribution to a Google open source project. Before we can look at your pull request, you'll need to sign a Contributor License Agreement (CLA).

View this failed invocation of the CLA check for more information.

For the most up to date status, view the checks section at the bottom of the pull request.

@Mola-maker
Mola-maker force-pushed the fix/pep-758-exception-lists branch from cb54c91 to 1a8a6a4 Compare September 30, 2026 06:35
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.

Support Python 3.14 unparenthesized exception lists (PEP 758)

1 participant