Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Very obscure edge case with __debug__ #2541

Open
00001H opened this issue Jan 3, 2025 · 0 comments
Open

Very obscure edge case with __debug__ #2541

00001H opened this issue Jan 3, 2025 · 0 comments

Comments

@00001H
Copy link

00001H commented Jan 3, 2025

If __debug__ is present in globals(), then the globals() value is read instead of the actual __debug__ value. However, the write is still attempted to the real __debug__, which fails. (or maybe it failed early when it detected a write to __debug__)

Python 3.13.0 (tags/v3.13.0:60403a5, Oct  7 2024, 09:38:07) [MSC v.1941 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license()" for more information.
>>> __debug__
True
>>> __debug__ = False
SyntaxError: cannot assign to __debug__
>>> globals()["__debug__"]
Traceback (most recent call last):
  File "<pyshell#2>", line 1, in <module>
    globals()["__debug__"]
KeyError: '__debug__'
>>> globals()["__debug__"] = "Hello"
>>> __debug__
True
>>> __debug__ = 3
SyntaxError: cannot assign to __debug__
>>>
Brython 3.13.0 on Netscape 5.0 (Windows)
Type "help", "copyright", "credits" or "license" for more information.
>>> __debug__
True
>>> __debug__ = False
File "<stdin>", line 1
    __debug__ = False
    ^^^^^^^^^
SyntaxError: cannot assign to __debug__
>>> globals()["__debug__"]
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
KeyError: __debug__
>>> globals()["__debug__"] = "Hello"
>>> __debug__
'Hello'
>>> __debug__ = 3
File "<stdin>", line 1
    __debug__ = 3
    ^^^^^^^^^
SyntaxError: cannot assign to __debug__
>>>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant