New submission from Serhiy Storchaka <storchaka+cpyt...@gmail.com>:

All ways of assigning to __debug__ are forbidden:

>>> __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__

The only exception is the assignment operator.

>>> (__debug__ := 'spam')
'spam'
>>> globals()['__debug__']
'spam'

This looks like a bug.

----------
components: Interpreter Core
messages: 336100
nosy: emilyemorehouse, gvanrossum, serhiy.storchaka
priority: normal
severity: normal
status: open
title: Assignment operator allows to assign to __debug__
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue36052>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to