Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

gh-131831: Implement PEP 758 – Allow except and except* expressions without parentheses #131833

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 10 commits into from
Apr 1, 2025
Prev Previous commit
Next Next commit
Apply suggestions from code review
Co-authored-by: BΓ©nΓ©dikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
  • Loading branch information
3 people authored Mar 29, 2025
commit 0d09ad2e1f79d85b58b10d6156ac0e9f4764267d
23 changes: 13 additions & 10 deletions 23 Doc/whatsnew/3.14.rst
Original file line number Diff line number Diff line change
Expand Up @@ -90,28 +90,31 @@ If you encounter :exc:`NameError`\s or pickling errors coming out of
New features
============

.. _whatsnew314-pep758:

PEP 758 – Allow except and except* expressions without parentheses
pablogsal marked this conversation as resolved.
Show resolved Hide resolved
------------------------------------------------------------------

The :keyword:`except` and :keyword:`except*` expressions now allow
The :keyword:`except` and :keyword:`except* <except_star>` expressions now allow
parentheses to be omitted when there is only one exception type.
pablogsal marked this conversation as resolved.
Show resolved Hide resolved
pablogsal marked this conversation as resolved.
Show resolved Hide resolved
For example the following expressions are now valid:

.. code-block:: python

try:
release_new_sleep_token_album()
except AlbumNotFound, SongsTooGoodToBeReleased:
print("Sorry, no new album this year.")
try:
release_new_sleep_token_album()
except AlbumNotFound, SongsTooGoodToBeReleased:
print("Sorry, no new album this year.")

pablogsal marked this conversation as resolved.
Show resolved Hide resolved
try:
release_new_sleep_token_album()
except* AlbumNotFound, SongsTooGoodToBeReleased:
print("Sorry, no new album this year.")
try:
release_new_sleep_token_album()
except* AlbumNotFound, SongsTooGoodToBeReleased:
print("Sorry, no new album this year.")

Check :pep:`758` for more details.

(Contributed by Pablo Galindo and Brett Cannon in :issue:`131831`.)
(Contributed by Pablo Galindo and Brett Cannon in :gh:`131831`.)


.. _whatsnew314-pep649:

Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.