[Python-checkins] bpo-43149: Correct the syntax error message for multiple exception types (GH-25996) GH-25997)
pablogsal
webhook-mailer at python.org
Sun May 9 17:14:09 EDT 2021
https://github.com/python/cpython/commit/9a0e65c8e05fdcd2207650d216ebdacdf0a025e9
commit: 9a0e65c8e05fdcd2207650d216ebdacdf0a025e9
branch: 3.10
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: pablogsal <Pablogsal at gmail.com>
date: 2021-05-09T22:13:50+01:00
summary:
bpo-43149: Correct the syntax error message for multiple exception types (GH-25996) GH-25997)
Automerge-Triggered-By: GH:pablogsal
(cherry picked from commit 6692dc1ca99fb34a19d0a4b93cf8e10619490001)
Co-authored-by: Pablo Galindo <Pablogsal at gmail.com>
Co-authored-by: Pablo Galindo <Pablogsal at gmail.com>
files:
A Misc/NEWS.d/next/Core and Builtins/2021-05-08-17-18-37.bpo-43149.Kp5FxD.rst
M Doc/whatsnew/3.10.rst
M Grammar/python.gram
M Lib/test/test_syntax.py
M Parser/parser.c
diff --git a/Doc/whatsnew/3.10.rst b/Doc/whatsnew/3.10.rst
index cfc560e1f4435f..2c6569fccd624d 100644
--- a/Doc/whatsnew/3.10.rst
+++ b/Doc/whatsnew/3.10.rst
@@ -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`)
diff --git a/Grammar/python.gram b/Grammar/python.gram
index 2f553c6d390c71..6b815ab0c518d4 100644
--- a/Grammar/python.gram
+++ b/Grammar/python.gram
@@ -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:
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 9799697b87d3b1..58407212b492f7 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -1068,7 +1068,7 @@
...
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:
@@ -1076,21 +1076,21 @@
... 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
@@ -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)
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-05-08-17-18-37.bpo-43149.Kp5FxD.rst b/Misc/NEWS.d/next/Core and Builtins/2021-05-08-17-18-37.bpo-43149.Kp5FxD.rst
new file mode 100644
index 00000000000000..cc1983ec3d4648
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and Builtins/2021-05-08-17-18-37.bpo-43149.Kp5FxD.rst
@@ -0,0 +1,2 @@
+Corrent the syntax error message regarding multiple exception types to not
+refer to "exception groups". Patch by Pablo Galindo
diff --git a/Parser/parser.c b/Parser/parser.c
index 6958963dfa39cf..2ca628b59ba869 100644
--- a/Parser/parser.c
+++ b/Parser/parser.c
@@ -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--);
More information about the Python-checkins
mailing list