Trying to assign a value to __debug__ using the assignment operator is supposed to fail, but
a missing check for forbidden names when setting the context in the ast was preventing this behaviour.
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
--- /dev/null
+Raise a :exc:`SyntaxError` when assigning a value to `__debug__` with the
+Assignment Operator. Contributed by Stéphane Wirtel and Pablo Galindo.
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() */
}