[docs] [issue34464] There are inconsitencies in the treatment of True, False, None, and __debug__ keywords in the docs

Serhiy Storchaka report at bugs.python.org
Wed Feb 20 10:18:59 EST 2019


Serhiy Storchaka <storchaka+cpython at gmail.com> added the comment:

__debug__ is not a keyword. And the error message has been changed in 3.8.

But it is a special enough. You can not use this name in any assignment context:

>>> __debug__ = 1
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> for __debug__ in []: pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> with cm() as __debug__: pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> class __debug__: pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> def __debug__(): pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> def foo(__debug__): pass
... 
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__
>>> import __debug__
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__

You can not even assign to an attribute named __debug__!

>>> x.__debug__ = 1
  File "<stdin>", line 1
SyntaxError: cannot assign to __debug__

The assignment operator is the only exception here, and this looks like a bug.

----------
nosy: +serhiy.storchaka

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue34464>
_______________________________________


More information about the docs mailing list