-
-
Notifications
You must be signed in to change notification settings - Fork 33.8k
Closed as not planned
Labels
type-featureA feature request or enhancementA feature request or enhancement
Description
Feature or enhancement
Proposal:
Currently, in Python, if you want an except block to handle multiple exception types, you use a comma to create a tuple of exceptions. For example:
try:
...
except ValueError,TypeError:
...
except Exception:
...In Python 3.14, the need for parentheses around multiple exceptions has been removed, simplifying the syntax slightly.
However, from a readability standpoint, the most “Pythonic” approach might be to use the or keyword, since it reads more like natural English. Conceptually, this is similar to manually checking the exception type:
try:
...
except Exception as e:
if isinstance(e,ValueError) or isinstance(e,TypeError)In an ideal syntax, one could imagine writing:
try:
...
except ValueError or TypeError:
...
except Exception:
...Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Metadata
Metadata
Assignees
Labels
type-featureA feature request or enhancementA feature request or enhancement