PEP 758: Small updates to PEG syntax and formatting (#4013)
This commit is contained in:
parent
668beb0cde
commit
a65bbd2d28
|
@ -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:
|
||||
|
|
Loading…
Reference in New Issue