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

bpo-43149: Correct the syntax error message for multiple exception types #25996

Merged
merged 1 commit into from
May 8, 2021
Merged
Show file tree
Hide file tree
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
2 changes: 1 addition & 1 deletion Doc/whatsnew/3.10.rst
Original file line number Diff line number Diff line change
Expand Up @@ -248,7 +248,7 @@ have been incorporated. Some of the most notable ones:
File "<stdin>", line 3
except NotEnoughScienceError, NotEnoughResourcesError:
^
SyntaxError: exception group must be parenthesized
SyntaxError: multiple exception types must be parenthesized

(Contributed by Pablo Galindo in :issue:`43149`)

Expand Down
2 changes: 1 addition & 1 deletion Grammar/python.gram
Original file line number Diff line number Diff line change
Expand Up @@ -956,7 +956,7 @@ invalid_try_stmt:
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
invalid_except_stmt:
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "exception group must be parenthesized") }
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
| a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
invalid_finally_stmt:
Expand Down
10 changes: 5 additions & 5 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -1068,29 +1068,29 @@
...
SyntaxError: invalid syntax

Check that an exception group with missing parentheses
Check that an multiple exception types with missing parentheses
raise a custom exception

>>> try:
... pass
... except A, B:
... pass
Traceback (most recent call last):
SyntaxError: exception group must be parenthesized
SyntaxError: multiple exception types must be parenthesized

>>> try:
... pass
... except A, B, C:
... pass
Traceback (most recent call last):
SyntaxError: exception group must be parenthesized
SyntaxError: multiple exception types must be parenthesized

>>> try:
... pass
... except A, B, C as blech:
... pass
Traceback (most recent call last):
SyntaxError: exception group must be parenthesized
SyntaxError: multiple exception types must be parenthesized

>>> try:
... pass
Expand All @@ -1099,7 +1099,7 @@
... finally:
... pass
Traceback (most recent call last):
SyntaxError: exception group must be parenthesized
SyntaxError: multiple exception types must be parenthesized


>>> f(a=23, a=234)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Corrent the syntax error message regarding multiple exception types to not
refer to "exception groups". Patch by Pablo Galindo
2 changes: 1 addition & 1 deletion Parser/parser.c
Original file line number Diff line number Diff line change
Expand Up @@ -19978,7 +19978,7 @@ invalid_except_stmt_rule(Parser *p)
)
{
D(fprintf(stderr, "%*c+ invalid_except_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'except' expression ',' expressions ['as' NAME] ':'"));
_res = RAISE_SYNTAX_ERROR_STARTING_FROM ( a , "exception group must be parenthesized" );
_res = RAISE_SYNTAX_ERROR_STARTING_FROM ( a , "multiple exception types must be parenthesized" );
if (_res == NULL && PyErr_Occurred()) {
p->error_indicator = 1;
D(p->level--);
Expand Down