[Python-checkins] bpo-39176: Improve error message for 'named assignment' (GH-17777) (GH-17778)
Raymond Hettinger
webhook-mailer at python.org
Tue Dec 31 22:28:12 EST 2019
https://github.com/python/cpython/commit/6c004955aceb8a0cd8e14afbc608ebfdf7c8aa4a
commit: 6c004955aceb8a0cd8e14afbc608ebfdf7c8aa4a
branch: 3.8
author: Miss Islington (bot) <31488909+miss-islington at users.noreply.github.com>
committer: Raymond Hettinger <rhettinger at users.noreply.github.com>
date: 2019-12-31T21:28:08-06:00
summary:
bpo-39176: Improve error message for 'named assignment' (GH-17777) (GH-17778)
(cherry picked from commit 37143a8e3b2e9245d52f4ddebbdd1c6121c96884)
Co-authored-by: Ned Batchelder <ned at nedbatchelder.com>
Co-authored-by: Ned Batchelder <ned at nedbatchelder.com>
files:
M Lib/test/test_named_expressions.py
M Lib/test/test_syntax.py
M Python/ast.c
diff --git a/Lib/test/test_named_expressions.py b/Lib/test/test_named_expressions.py
index 01e26c8dfaf25..3ae557f78d273 100644
--- a/Lib/test/test_named_expressions.py
+++ b/Lib/test/test_named_expressions.py
@@ -32,7 +32,7 @@ def test_named_expression_invalid_04(self):
def test_named_expression_invalid_06(self):
code = """((a, b) := (1, 2))"""
- with self.assertRaisesRegex(SyntaxError, "cannot use named assignment with tuple"):
+ with self.assertRaisesRegex(SyntaxError, "cannot use assignment expressions with tuple"):
exec(code, {}, {})
def test_named_expression_invalid_07(self):
@@ -90,7 +90,7 @@ def test_named_expression_invalid_15(self):
code = """(lambda: x := 1)"""
with self.assertRaisesRegex(SyntaxError,
- "cannot use named assignment with lambda"):
+ "cannot use assignment expressions with lambda"):
exec(code, {}, {})
def test_named_expression_invalid_16(self):
diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py
index 3829746f1799a..128c4da143841 100644
--- a/Lib/test/test_syntax.py
+++ b/Lib/test/test_syntax.py
@@ -45,7 +45,7 @@
>>> (True := 1)
Traceback (most recent call last):
-SyntaxError: cannot use named assignment with True
+SyntaxError: cannot use assignment expressions with True
>>> obj.__debug__ = 1
Traceback (most recent call last):
diff --git a/Python/ast.c b/Python/ast.c
index e70ab519e66e1..6cf71ce7bb810 100644
--- a/Python/ast.c
+++ b/Python/ast.c
@@ -1955,7 +1955,7 @@ ast_for_namedexpr(struct compiling *c, const node *n)
if (target->kind != Name_kind) {
const char *expr_name = get_expr_name(target);
if (expr_name != NULL) {
- ast_error(c, n, "cannot use named assignment with %s", expr_name);
+ ast_error(c, n, "cannot use assignment expressions with %s", expr_name);
}
return NULL;
}
More information about the Python-checkins
mailing list