Skip to content

Commit

Permalink
bpo-39176: Improve error message for 'named assignment' (GH-17777) (G…
Browse files Browse the repository at this point in the history
…H-17778)

(cherry picked from commit 37143a8)

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>

Co-authored-by: Ned Batchelder <ned@nedbatchelder.com>
  • Loading branch information
2 people authored and rhettinger committed Jan 1, 2020
1 parent 302b35f commit 6c00495
Show file tree
Hide file tree
Showing 3 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions Lib/test/test_named_expressions.py
Expand Up @@ -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):
Expand Down Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Lib/test/test_syntax.py
Expand Up @@ -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):
Expand Down
2 changes: 1 addition & 1 deletion Python/ast.c
Expand Up @@ -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;
}
Expand Down

0 comments on commit 6c00495

Please sign in to comment.