Message295908
Docs mention:
ast.parse(source, filename='<unknown>', mode='exec')
Parse the source into an AST node. Equivalent to compile(source, filename, mode, ast.PyCF_ONLY_AST).
If you just parse code into AST, you first check whether it is possible to turn such source into a Python syntax tree. In that case, it obviously is, as you may imagine a function, that returns nothing:
def func():
return
If however you try to make executable code of the source, it is checked whether the constructs make sense in provided context. And, as you may imagine, top-level code with return statement is not valid, hence the error. |
|
Date |
User |
Action |
Args |
2017-06-13 11:53:12 | enedil | set | recipients:
+ enedil, hniksic |
2017-06-13 11:53:12 | enedil | set | messageid: <1497354792.93.0.568113770717.issue30637@psf.upfronthosting.co.za> |
2017-06-13 11:53:12 | enedil | link | issue30637 messages |
2017-06-13 11:53:12 | enedil | create | |
|