Skip to content

Docs: except with multiple exceptions parentheses not required#145848

Open
duilio wants to merge 1 commit intopython:mainfrom
duilio:patch-1
Open

Docs: except with multiple exceptions parentheses not required#145848
duilio wants to merge 1 commit intopython:mainfrom
duilio:patch-1

Conversation

@duilio
Copy link

@duilio duilio commented Mar 12, 2026

As of PEP 758 the except statement doesn't require parentheses anymore for exception tuples.

See: https://peps.python.org/pep-0758/


📚 Documentation preview 📚: https://cpython-previews--145848.org.readthedocs.build/

As of PEP 758 the except statement doesn't require parentheses anymore for exception tuples.

See: https://peps.python.org/pep-0758/
@bedevere-app bedevere-app bot added docs Documentation in the Doc dir skip news labels Mar 12, 2026
@python-cla-bot
Copy link

python-cla-bot bot commented Mar 12, 2026

All commit authors signed the Contributor License Agreement.

CLA signed

Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I prefer the old style rather than the style personally, so I don't think we should remove one for the other. The entire library is till using the old style and we won't be switching to the new style as the old one is still fine and the most common.

For the tutorial, I'd prefer that we leave it as is (as otherwise, newcomers will be confused with existing code).

@picnixz picnixz closed this Mar 12, 2026
@picnixz picnixz reopened this Mar 12, 2026
Copy link
Member

@picnixz picnixz left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry, I didn't want to close the PR. I wanted to ask for changes by telling that it is possible to use a non-parenthized form though I don't know if it has its place in the tutorial (should we advocate for multiple forms or not? the same can be said with multilines with statements where before we needed nested ones).

@bedevere-app
Copy link

bedevere-app bot commented Mar 12, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@picnixz
Copy link
Member

picnixz commented Mar 12, 2026

cc @hugovk @nedbat for their teaching's opinion and @pablogsal as the PEP-758's author

@nedbat
Copy link
Member

nedbat commented Mar 12, 2026

I would write:

An *except clause* may name multiple exceptions, for example::

   ... except RuntimeError, TypeError, NameError:
   ...     pass

The parentheses are not necessary, and "as a tuple" is distracting. The point of the paragraph is to show that multiple exceptions can be named, and this is the simplest way to show that.

Other code may use parentheses, but I don't think that will be a stumbling block. People are used to parentheses being optional for clarity, and there are bigger things people will need to understand as they progress from simple exception examples in the tutorial to real code.

@picnixz
Copy link
Member

picnixz commented Mar 12, 2026

I understand the reason and won't block on it

Handlers only handle exceptions that occur in the corresponding *try clause*,
not in other handlers of the same :keyword:`!try` statement. An *except clause*
may name multiple exceptions as a parenthesized tuple, for example::
may name multiple exceptions as a tuple, for example::
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
may name multiple exceptions as a tuple, for example::
may name multiple exceptions, for example::

@bedevere-app
Copy link

bedevere-app bot commented Mar 12, 2026

A Python core developer has requested some changes be made to your pull request before we can consider merging it. If you could please address their requests along with any other requests in other reviews from core developers that would be appreciated.

Once you have made the requested changes, please leave a comment on this pull request containing the phrase I have made the requested changes; please review again. I will then notify any core developers who have left a review that you're ready for them to take another look at this pull request.

@hugovk hugovk added the needs backport to 3.14 bugs and security fixes label Mar 12, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes docs Documentation in the Doc dir needs backport to 3.14 bugs and security fixes skip issue skip news

Projects

Status: Todo

Development

Successfully merging this pull request may close these issues.

4 participants