diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index ce1de4b319f20f..a0f487d4ed76b4 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -51,6 +51,10 @@ Traceback (most recent call last): SyntaxError: cannot assign to __debug__ +>>> (__debug__ := 1) +Traceback (most recent call last): +SyntaxError: cannot assign to __debug__ + >>> f() = 1 Traceback (most recent call last): SyntaxError: cannot assign to function call diff --git a/Python/ast.c b/Python/ast.c index 5cef3fdadc9ae9..8482a615035b4d 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -1084,7 +1084,7 @@ set_context(struct compiling *c, expr_ty e, expr_context_ty ctx, const node *n) return 0; break; case Name_kind: - if (ctx == Store) { + if (ctx == Store || ctx == NamedStore) { if (forbidden_name(c, e->v.Name.id, n, 0)) return 0; /* forbidden_name() calls ast_error() */ }