Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions Lib/test/test_syntax.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Raise a :exc:`SyntaxError` when assigning a value to `__debug__` with the
Assignment Operator. Contributed by Stéphane Wirtel and Pablo Galindo.
2 changes: 1 addition & 1 deletion Python/ast.c
Original file line number Diff line number Diff line change
Expand Up @@ -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() */
}
Expand Down