This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Deleting __debug__ should be an SyntaxError
Type: enhancement Stage: resolved
Components: Interpreter Core Versions: Python 3.11
process
Status: closed Resolution: out of date
Dependencies: Superseder:
Assigned To: Nosy List: Carl.Friedrich.Bolz, aroberge, pablogsal, terry.reedy
Priority: normal Keywords:

Created on 2021-11-11 09:45 by Carl.Friedrich.Bolz, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (5)
msg406149 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-11-11 09:45
Right now, deleting __debug__ is not prevented:

>>> def f():
...     del __debug__
... 

Of course actually executing it doesn't work:

>>> del __debug__
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
NameError: name '__debug__' is not defined


Compare with assigning to __debug__:

>>> def f():
...     __debug__ = 1
... 
  File "<stdin>", line 2
SyntaxError: cannot assign to __debug__
msg406248 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-11-12 22:36
For comparison:

True = 0
SyntaxError: cannot assign to True
del True
SyntaxError: cannot delete True

It almost seems like __debug__ is a hidden keyword value, but with a startup-dependent value
msg406250 - (view) Author: Andre Roberge (aroberge) * Date: 2021-11-12 23:00
What version are you using?  As far as I can test, it has become a syntax error since 3.10. Here is the result with the latest 3.11 alpha

> python
Python 3.11.0a2 (tags/v3.11.0a2:e2b4e4b, Nov  5 2021, 20:00:05) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> del __debug__
  File "<stdin>", line 1
SyntaxError: cannot delete __debug__
>>> exit()

> python
Python 3.11.0a2 (tags/v3.11.0a2:e2b4e4b, Nov  5 2021, 20:00:05) [MSC v.1929 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> def f():
...    del __debug__
...
  File "<stdin>", line 2
SyntaxError: cannot delete __debug__
msg406251 - (view) Author: Terry J. Reedy (terry.reedy) * (Python committer) Date: 2021-11-12 23:04
Verified in IDLE also.  Thanks for doing the test I should have done.
msg406277 - (view) Author: Carl Friedrich Bolz-Tereick (Carl.Friedrich.Bolz) * Date: 2021-11-13 13:03
ouch, apologies for not checking that!
History
Date User Action Args
2022-04-11 14:59:52adminsetgithub: 89939
2021-11-13 13:03:27Carl.Friedrich.Bolzsetmessages: + msg406277
2021-11-12 23:04:14terry.reedysetstatus: open -> closed
resolution: out of date
messages: + msg406251

stage: test needed -> resolved
2021-11-12 23:00:53arobergesetnosy: + aroberge
messages: + msg406250
2021-11-12 22:36:58terry.reedysettype: enhancement
components: + Interpreter Core
versions: + Python 3.11
nosy: + pablogsal, terry.reedy

messages: + msg406248
stage: test needed
2021-11-11 09:45:11Carl.Friedrich.Bolzcreate