[New-bugs-announce] [issue41897] ast.parse in Python 3.9 does not produce SyntaxError for assignment to __debug__

Saiyang Gou report at bugs.python.org
Wed Sep 30 14:55:04 EDT 2020


New submission from Saiyang Gou <gousaiyang223 at gmail.com>:

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.

----------
components: Library (Lib)
messages: 377717
nosy: gousaiyang
priority: normal
severity: normal
status: open
title: ast.parse in Python 3.9 does not produce SyntaxError for assignment to __debug__
type: enhancement
versions: Python 3.9

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


More information about the New-bugs-announce mailing list