Skip to content

except using "or" keyword #143355

@HumanBot000

Description

@HumanBot000

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

No one assigned

    Labels

    type-featureA feature request or enhancement

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions