[issue40378] ast.parse fails to trigger SyntaxWarning that normal execution does

Serhiy Storchaka report at bugs.python.org
Sat Apr 25 02:50:06 EDT 2020


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

Compilation includes the following stages:

1. Tokenizing.
2. Creating CST (concrete syntax tree).
3. Creating AST (abstract syntax tree).
4. Optimizing AST.
5. Building symtable.
6. Generating bytecode.
7. Optimizing bytecode.

ast.parse() only includes stages 1-3. Many warnings and errors can be raised at stages 5 and 6 (for example errors for "break" outside of a loop and "unlocal" at module level). If you want to get all warnings and errors, use compile().

----------

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


More information about the Python-bugs-list mailing list