Skip to content

Commit

Permalink
bpo-45000: Raise SyntaxError when try to delete __debug__ (GH-27947) (G…
Browse files Browse the repository at this point in the history
…H-27957)

(cherry picked from commit 551da59)
  • Loading branch information
corona10 committed Aug 26, 2021
1 parent 6ea6cf2 commit 32c1caa
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 0 deletions.
4 changes: 4 additions & 0 deletions Lib/test/test_syntax.py
Expand Up @@ -59,6 +59,10 @@
Traceback (most recent call last):
SyntaxError: cannot assign to __debug__
>>> del __debug__
Traceback (most recent call last):
SyntaxError: cannot delete __debug__
>>> f() = 1
Traceback (most recent call last):
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
Expand Down
@@ -0,0 +1,2 @@
A :exc:`SyntaxError` is now raised when trying to delete :const:`__debug__`.
Patch by Dong-hee Na.
4 changes: 4 additions & 0 deletions Python/compile.c
Expand Up @@ -2264,6 +2264,10 @@ forbidden_name(struct compiler *c, identifier name, expr_context_ty ctx)
compiler_error(c, "cannot assign to __debug__");
return 1;
}
if (ctx == Del && _PyUnicode_EqualToASCIIString(name, "__debug__")) {
compiler_error(c, "cannot delete __debug__");
return 1;
}
return 0;
}

Expand Down

0 comments on commit 32c1caa

Please sign in to comment.