8000 bpo-45000: Raise SyntaxError when try to delete __debug__ (GH-27947) … · python/cpython@32c1caa · GitHub
[go: up one dir, main page]

Skip to content

Commit 32c1caa

Browse files
authored
bpo-45000: Raise SyntaxError when try to delete __debug__ (GH-27947) (GH-27957)
(cherry picked from commit 551da59)
1 parent 6ea6cf2 commit 32c1caa

File tree

3 files changed

+10
-0
lines changed

3 files changed

+10
-0
lines changed

Lib/test/test_syntax.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,10 @@
5959
Traceback (most recent call last):
6060
SyntaxError: cannot assign to __debug__
6161
62+
>>> del __debug__
63+
Traceback (most recent call last):
64+
SyntaxError: cannot delete __debug__
65+
6266
>>> f() = 1
6367
Traceback (most recent call last):
6468
SyntaxError: cannot assign to function call here. Maybe you meant '==' instead of '='?
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
A :exc:`SyntaxError` is now raised when trying to delete :const:`__debug__`.
2+
Patch by Dong-hee Na.

Python/compile.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2264,6 +2264,10 @@ forbidden_name(struct compiler *c, identifier name, expr_context_ty ctx)
22642264
compiler_error(c, "cannot assign to __debug__");
22652265
return 1;
22662266
}
2267+
if (ctx == Del && _PyUnicode_EqualToASCIIString(name, "__debug__")) {
2268+
compiler_error(c, "cannot delete __debug__");
2269+
return 1;
2270+
}
22672271
return 0;
22682272
}
22692273

0 commit comments

Comments
 (0)
0