Skip to content

Commit

Permalink
PEP 758: Small updates to PEG syntax and formatting (#4013)
Browse files Browse the repository at this point in the history
  • Loading branch information
pablogsal authored Oct 1, 2024
1 parent 668beb0 commit a65bbd2
Showing 1 changed file with 10 additions and 14 deletions.
24 changes: 10 additions & 14 deletions peps/pep-0758.rst
Original file line number Diff line number Diff line change
Expand Up @@ -75,12 +75,14 @@ The decision to allow unparenthesized ``except`` blocks is based on the
following considerations:

1. Simplicity: Removing the requirement for parentheses simplifies the syntax,
making it more consistent with other parts of the language.
making it more consistent with other parts of the language.

2. Readability: In cases where many exceptions are being caught, the removal of
parentheses can improve readability by reducing visual clutter.
parentheses can improve readability by reducing visual clutter.

3. Consistency: This change makes the ``except`` clause more consistent with other parts of Python where unambiguous, comma-separated lists don't require parentheses.
3. Consistency: This change makes the ``except`` clause more consistent with
other parts of Python where unambiguous, comma-separated lists don't require
parentheses.

Specification
=============
Expand All @@ -90,18 +92,12 @@ list of exception types. The grammar will be updated as follows:

.. code-block:: peg
except_block[excepthandler_ty]:
| invalid_except_stmt_indent
| 'except' e=expressions t=['as' z=NAME { z }] ':' b=block {
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
| 'except' ':' b=block { _PyAST_ExceptHandler(NULL, NULL, b, EXTRA) }
| invalid_except_stmt
except_star_block[excepthandler_ty]:
| invalid_except_star_stmt_indent
| 'except' '*' e=expressions t=['as' z=NAME { z }] ':' b=block {
_PyAST_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
| invalid_except_star_stmt
except_block:
| 'except' expressions ['as' NAME] ':' block
| 'except' ':' block
except_star_block
| 'except' '*' expressions ['as' NAME] ':' block
This allows both the current parenthesized syntax and the new unparenthesized
syntax:
Expand Down

0 comments on commit a65bbd2

Please sign in to comment.