Skip to content

Commit

Permalink
Apply suggestions from code review
Browse files Browse the repository at this point in the history
Co-authored-by: Hugo van Kemenade <[email protected]>
Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Adam Turner <[email protected]>
Co-authored-by: Alex Waygood <[email protected]>
  • Loading branch information
5 people authored Oct 7, 2024
1 parent bba0c27 commit 217fc52
Showing 1 changed file with 15 additions and 17 deletions.
32 changes: 15 additions & 17 deletions peps/pep-0760.rst
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@
PEP: 760
Title: No More Bare Excepts
Author: Pablo Galindo <[email protected]>, Brett Cannon <[email protected]>
PEP-Delegate: TBD
Status: Draft
Type: Standards Track
Created: 30-Sep-2024
Created: 02-Oct-2024
Python-Version: 3.14


Expand All @@ -22,7 +21,7 @@ error handling.
Motivation
==========

The current syntax allows for catching all exceptions with a bare ``except:`` clause is:
The current syntax allows for catching all exceptions with a bare ``except:`` clause:

.. code-block:: python
Expand Down Expand Up @@ -79,36 +78,36 @@ The syntax for the except clause will be modified to require an exception type.
The grammar will be updated to remove the possibility of adding an empty
expression in except clauses.

This change disallows the bare 'except:' syntax. All except clauses must
This change disallows the bare ``except:`` syntax. All except clauses must
specify at least one exception type:

.. code-block:: python
try:
...
except ValueError:
...
except (TypeError, RuntimeError):
...
except Exception:
... # Still allowed, but catches all exceptions explicitly
try:
...
except ValueError:
...
except (TypeError, RuntimeError):
...
except Exception:
... # Still allowed, but catches all exceptions explicitly
The semantics of exception handling remain unchanged, except that it will no
longer be possible to catch all exceptions without explicitly specifying
'Exception' or a similarly broad exception type.
``BaseException`` or a similarly broad exception type.


Backwards Compatibility
=======================

This change is not backwards compatible. Existing code that uses bare 'except:'
This change is not backwards compatible. Existing code that uses bare ``except:``
clauses will need to be modified. To ease the transition:

1. A deprecation warning will be issued for bare except clauses in Python 3.14.
2. The syntax will be fully disallowed in Python 3.15.

A tool will be provided to automatically update code to replace bare 'except:'
with 'except Exception:'.
A tool will be provided to automatically update code to replace bare ``except:``
with ``except BaseException:``.


Security Implications
Expand Down Expand Up @@ -159,4 +158,3 @@ CC0-1.0-Universal license, whichever is more permissive.
.. [6] https://4.docs.plone.org/develop/plone-coredev/style.html#concrete-rules
.. [7] https://docs.openedx.org/en/latest/developers/references/developer_guide/style_guides/python-guidelines.html

0 comments on commit 217fc52

Please sign in to comment.