aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPablo Galindo <Pablogsal@gmail.com>2021-02-07 18:42:21 +0000
committerGitHub <noreply@github.com>2021-02-07 18:42:21 +0000
commit206cbdab16cb054e859597a562e2f6ab35e99766 (patch)
tree005cf5c7f838019da4ea52eb0ad21e7511672ac5 /Grammar
parentbpo-16781: In 'exec' doc, add 'nonlocal' to 'yield' and 'return' (GH-2446) (diff)
downloadcpython-206cbdab16cb054e859597a562e2f6ab35e99766.tar.gz
cpython-206cbdab16cb054e859597a562e2f6ab35e99766.tar.bz2
cpython-206cbdab16cb054e859597a562e2f6ab35e99766.zip
bpo-43149: Improve error message for exception group without parentheses (GH-24467)
Diffstat (limited to 'Grammar')
-rw-r--r--Grammar/python.gram11
1 files changed, 9 insertions, 2 deletions
diff --git a/Grammar/python.gram b/Grammar/python.gram
index d1a36f0e4d0..bb70bbb565d 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -201,9 +201,10 @@ try_stmt[stmt_ty]:
| 'try' &&':' b=block f=finally_block { _Py_Try(b, NULL, NULL, f, EXTRA) }
| 'try' &&':' b=block ex[asdl_excepthandler_seq*]=except_block+ el=[else_block] f=[finally_block] { _Py_Try(b, ex, el, f, EXTRA) }
except_block[excepthandler_ty]:
- | 'except' e=expression t=['as' z=NAME { z }] &&':' b=block {
+ | 'except' e=expression t=['as' z=NAME { z }] ':' b=block {
_Py_ExceptHandler(e, (t) ? ((expr_ty) t)->v.Name.id : NULL, b, EXTRA) }
- | 'except' &&':' b=block { _Py_ExceptHandler(NULL, NULL, b, EXTRA) }
+ | 'except' ':' b=block { _Py_ExceptHandler(NULL, NULL, b, EXTRA) }
+ | invalid_except_block
finally_block[asdl_stmt_seq*]: 'finally' ':' a=block { a }
return_stmt[stmt_ty]:
@@ -737,3 +738,9 @@ invalid_import_from_targets:
invalid_with_stmt:
| [ASYNC] 'with' ','.(expression ['as' star_target])+ &&':'
| [ASYNC] 'with' '(' ','.(expressions ['as' star_target])+ ','? ')' &&':'
+
+invalid_except_block:
+ | 'except' a=expression ',' expressions ['as' NAME ] ':' {
+ RAISE_SYNTAX_ERROR_KNOWN_LOCATION(a, "exception group must be parenthesized") }
+ | 'except' expression ['as' NAME ] &&':'
+ | 'except' &&':'