]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-45000: Raise SyntaxError when try to delete __debug__ (GH-27947)
authorDong-hee Na <donghee.na@python.org>
Wed, 25 Aug 2021 17:54:20 +0000 (17:54 +0000)
committerGitHub <noreply@github.com>
Wed, 25 Aug 2021 17:54:20 +0000 (10:54 -0700)
Automerge-Triggered-By: GH:pablogsal
Doc/whatsnew/3.11.rst
Lib/test/test_syntax.py
Misc/NEWS.d/next/Core and Builtins/2021-08-25-23-17-32.bpo-45000.XjmyLl.rst [new file with mode: 0644]
Python/compile.c

index 306385c2a90aaf93ea422b2ef02dbc58ada2327b..296b1b279d09bb21b1f6afe20f8ba34f80d50f60 100644 (file)
@@ -176,6 +176,8 @@ Other CPython Implementation Changes
   support :class:`typing.SupportsComplex` and :class:`typing.SupportsBytes` protocols.
   (Contributed by Mark Dickinson and Dong-hee Na in :issue:`24234`.)
 
+*  A :exc:`SyntaxError` (instead of a :exc:`NameError`) will be raised when deleting the :const:`__debug__` constant. (Contributed by Dong-hee Na in :issue:`45000`.)
+
 
 New Modules
 ===========
index 88503dcaad99b79f209a2c3a5a8a76815ea42072..43780ce273ef4ee6e2cb42c665e200c71e417567 100644 (file)
@@ -59,6 +59,10 @@ SyntaxError: cannot assign to __debug__
 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 '='?
diff --git a/Misc/NEWS.d/next/Core and Builtins/2021-08-25-23-17-32.bpo-45000.XjmyLl.rst b/Misc/NEWS.d/next/Core and Builtins/2021-08-25-23-17-32.bpo-45000.XjmyLl.rst
new file mode 100644 (file)
index 0000000..96c95cc
--- /dev/null
@@ -0,0 +1,2 @@
+A :exc:`SyntaxError` is now raised when trying to delete :const:`__debug__`.
+Patch by Dong-hee Na.
index e651ca535191af3bf18cd8cf3b64f55968307c5b..053915e55df9a75f92a2fc9ee2a5e8729a8bd9cf 100644 (file)
@@ -2343,6 +2343,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;
 }