mirror of https://github.com/python/cpython
bpo-43149: Improve error message for exception group without parentheses (GH-24467)
This commit is contained in:
parent
0ec57e25c9
commit
206cbdab16
|
@ -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' &&':'
|
||||
|
|
|
@ -835,6 +835,39 @@ Make sure that the old "raise X, Y[, Z]" form is gone:
|
|||
...
|
||||
SyntaxError: invalid syntax
|
||||
|
||||
Check that an exception group with missing parentheses
|
||||
raise a custom exception
|
||||
|
||||
>>> try:
|
||||
... pass
|
||||
... except A, B:
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: exception group must be parenthesized
|
||||
|
||||
>>> try:
|
||||
... pass
|
||||
... except A, B, C:
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: exception group must be parenthesized
|
||||
|
||||
>>> try:
|
||||
... pass
|
||||
... except A, B, C as blech:
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: exception group must be parenthesized
|
||||
|
||||
>>> try:
|
||||
... pass
|
||||
... except A, B, C as blech:
|
||||
... pass
|
||||
... finally:
|
||||
... pass
|
||||
Traceback (most recent call last):
|
||||
SyntaxError: exception group must be parenthesized
|
||||
|
||||
|
||||
>>> f(a=23, a=234)
|
||||
Traceback (most recent call last):
|
||||
|
|
|
@ -0,0 +1,2 @@
|
|||
Improve the error message in the parser for exception groups without
|
||||
parentheses. Patch by Pablo Galindo.
|
1419
Parser/parser.c
1419
Parser/parser.c
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue