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: ast.parse in Python 3.9 does not produce SyntaxError for assignment to __debug__
Type: enhancement Stage: resolved
Components: Library (Lib) Versions: Python 3.9
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: Nosy List: BTaskaya, gousaiyang, gvanrossum, pablogsal
Priority: normal Keywords:

Created on 2020-09-30 18:55 by gousaiyang, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg377717 - (view) Author: Saiyang Gou (gousaiyang) * Date: 2020-09-30 18:55
ast.parse in Python 3.9 does not produce SyntaxError for assignment to __debug__:

```
>>> import ast
>>> ast.dump(ast.parse('__debug__ = 0'))
"Module(body=[Assign(targets=[Name(id='__debug__', ctx=Store())], value=Constant(value=0))], type_ignores=[])"
>>> exec('__debug__ = 0')
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
SyntaxError: cannot assign to __debug__
```

In Python 3.8 a SyntaxError was properly raised. Probably this is due to the new PEG parser.
msg377721 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2020-09-30 20:28
We moved the check from the parser to the bytecode compiler. I don't think this should be a problem. Kudos for noticing though! :-)

```
>>> compile("__debug__ = 1", "<string>", "exec")
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "<string>", line 1
SyntaxError: cannot assign to __debug__
>>> 
```
History
Date User Action Args
2022-04-11 14:59:36adminsetgithub: 86063
2020-09-30 20:28:55gvanrossumsetstatus: open -> closed
resolution: wont fix
messages: + msg377721

stage: resolved
2020-09-30 19:48:00serhiy.storchakasetnosy: + gvanrossum, pablogsal, BTaskaya
2020-09-30 18:55:04gousaiyangcreate