Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PEP 758: Small updates to PEG syntax and formatting #4013

Merged
merged 1 commit into from
Oct 1, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading