From a65bbd2d2865602d9fdcc3d8442d43cc835bb5b8 Mon Sep 17 00:00:00 2001 From: Pablo Galindo Salgado Date: Tue, 1 Oct 2024 23:47:21 +0100 Subject: [PATCH] PEP 758: Small updates to PEG syntax and formatting (#4013) --- peps/pep-0758.rst | 24 ++++++++++-------------- 1 file changed, 10 insertions(+), 14 deletions(-) diff --git a/peps/pep-0758.rst b/peps/pep-0758.rst index df3efa0e0c9..cffa85bb70e 100644 --- a/peps/pep-0758.rst +++ b/peps/pep-0758.rst @@ -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 ============= @@ -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: