Skip to content

Commit 37143a8

Browse files
nedbatrhettinger
authored andcommitted
bpo-39176: Improve error message for 'named assignment' (GH-17777)
1 parent ba82ee8 commit 37143a8

File tree

3 files changed

+4
-4
lines changed

3 files changed

+4
-4
lines changed

Lib/test/test_named_expressions.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@ def test_named_expression_invalid_04(self):
3232
def test_named_expression_invalid_06(self):
3333
code = """((a, b) := (1, 2))"""
3434

35-
with self.assertRaisesRegex(SyntaxError, "cannot use named assignment with tuple"):
35+
with self.assertRaisesRegex(SyntaxError, "cannot use assignment expressions with tuple"):
3636
exec(code, {}, {})
3737

3838
def test_named_expression_invalid_07(self):
@@ -90,7 +90,7 @@ def test_named_expression_invalid_15(self):
9090
code = """(lambda: x := 1)"""
9191

9292
with self.assertRaisesRegex(SyntaxError,
93-
"cannot use named assignment with lambda"):
93+
"cannot use assignment expressions with lambda"):
9494
exec(code, {}, {})
9595

9696
def test_named_expression_invalid_16(self):

Lib/test/test_syntax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -45,7 +45,7 @@
4545
4646
>>> (True := 1)
4747
Traceback (most recent call last):
48-
SyntaxError: cannot use named assignment with True
48+
SyntaxError: cannot use assignment expressions with True
4949
5050
>>> obj.__debug__ = 1
5151
Traceback (most recent call last):

Python/ast.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1955,7 +1955,7 @@ ast_for_namedexpr(struct compiling *c, const node *n)
19551955
if (target->kind != Name_kind) {
19561956
const char *expr_name = get_expr_name(target);
19571957
if (expr_name != NULL) {
1958-
ast_error(c, n, "cannot use named assignment with %s", expr_name);
1958+
ast_error(c, n, "cannot use assignment expressions with %s", expr_name);
19591959
}
19601960
return NULL;
19611961
}

0 commit comments

Comments
 (0)