Skip to content

Commit 6692dc1

Browse files
authored
bpo-43149: Correct the syntax error message for multiple exception types (GH-25996)
Automerge-Triggered-By: GH:pablogsal
1 parent 873275e commit 6692dc1

File tree

5 files changed

+10
-8
lines changed

5 files changed

+10
-8
lines changed

Doc/whatsnew/3.10.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -248,7 +248,7 @@ have been incorporated. Some of the most notable ones:
248248
File "<stdin>", line 3
249249
except NotEnoughScienceError, NotEnoughResourcesError:
250250
^
251-
SyntaxError: exception group must be parenthesized
251+
SyntaxError: multiple exception types must be parenthesized
252252
253253
(Contributed by Pablo Galindo in :issue:`43149`)
254254

Grammar/python.gram

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -956,7 +956,7 @@ invalid_try_stmt:
956956
RAISE_INDENTATION_ERROR("expected an indented block after 'try' statement on line %d", a->lineno) }
957957
invalid_except_stmt:
958958
| 'except' a=expression ',' expressions ['as' NAME ] ':' {
959-
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "exception group must be parenthesized") }
959+
RAISE_SYNTAX_ERROR_STARTING_FROM(a, "multiple exception types must be parenthesized") }
960960
| a='except' expression ['as' NAME ] NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
961961
| a='except' NEWLINE { RAISE_SYNTAX_ERROR("expected ':'") }
962962
invalid_finally_stmt:

Lib/test/test_syntax.py

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1068,29 +1068,29 @@
10681068
...
10691069
SyntaxError: invalid syntax
10701070
1071-
Check that an exception group with missing parentheses
1071+
Check that an multiple exception types with missing parentheses
10721072
raise a custom exception
10731073
10741074
>>> try:
10751075
... pass
10761076
... except A, B:
10771077
... pass
10781078
Traceback (most recent call last):
1079-
SyntaxError: exception group must be parenthesized
1079+
SyntaxError: multiple exception types must be parenthesized
10801080
10811081
>>> try:
10821082
... pass
10831083
... except A, B, C:
10841084
... pass
10851085
Traceback (most recent call last):
1086-
SyntaxError: exception group must be parenthesized
1086+
SyntaxError: multiple exception types must be parenthesized
10871087
10881088
>>> try:
10891089
... pass
10901090
... except A, B, C as blech:
10911091
... pass
10921092
Traceback (most recent call last):
1093-
SyntaxError: exception group must be parenthesized
1093+
SyntaxError: multiple exception types must be parenthesized
10941094
10951095
>>> try:
10961096
... pass
@@ -1099,7 +1099,7 @@
10991099
... finally:
11001100
... pass
11011101
Traceback (most recent call last):
1102-
SyntaxError: exception group must be parenthesized
1102+
SyntaxError: multiple exception types must be parenthesized
11031103
11041104
11051105
>>> f(a=23, a=234)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Corrent the syntax error message regarding multiple exception types to not
2+
refer to "exception groups". Patch by Pablo Galindo

Parser/parser.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19978,7 +19978,7 @@ invalid_except_stmt_rule(Parser *p)
1997819978
)
1997919979
{
1998019980
D(fprintf(stderr, "%*c+ invalid_except_stmt[%d-%d]: %s succeeded!\n", p->level, ' ', _mark, p->mark, "'except' expression ',' expressions ['as' NAME] ':'"));
19981-
_res = RAISE_SYNTAX_ERROR_STARTING_FROM ( a , "exception group must be parenthesized" );
19981+
_res = RAISE_SYNTAX_ERROR_STARTING_FROM ( a , "multiple exception types must be parenthesized" );
1998219982
if (_res == NULL && PyErr_Occurred()) {
1998319983
p->error_indicator = 1;
1998419984
D(p->level--);

0 commit comments

Comments
 (0)