]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-39176: Improve error message for 'named assignment' (GH-17777)
authorNed Batchelder <ned@nedbatchelder.com>
Wed, 1 Jan 2020 02:40:58 +0000 (21:40 -0500)
committerRaymond Hettinger <rhettinger@users.noreply.github.com>
Wed, 1 Jan 2020 02:40:58 +0000 (20:40 -0600)
Lib/test/test_named_expressions.py
Lib/test/test_syntax.py
Python/ast.c

index 01e26c8dfaf259c37c70b61d6a8f506467cc9392..3ae557f78d273a31ab03dffc05d53a8e4f24eee4 100644 (file)
@@ -32,7 +32,7 @@ class NamedExpressionInvalidTest(unittest.TestCase):
     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 @@ class NamedExpressionInvalidTest(unittest.TestCase):
         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):
index 3829746f1799a2211416d22abbc40731d6108045..128c4da14384143f8d133705e6b2807ab7864a89 100644 (file)
@@ -45,7 +45,7 @@ SyntaxError: cannot assign to True
 
 >>> (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):
index e4e9b837d34093398c578b96db78f0e07fccd3f3..d5113f8e413f499dc6f0519bc89a0e09d98d9122 100644 (file)
@@ -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;
     }