Message295771
Our application compiles snippets of user-specified code using the compile built-in with ast.PyCF_ONLY_AST flag. At this stage we catch syntax errors and perform some sanity checks on the AST. The AST is then compiled into actual code using compile() and run using further guards.
We found that using a bare "return" in the code works with ast.PyCF_ONLY_AST, but raises SyntaxError when compiled without the flag:
>>> import ast
>>> compile('return', '', 'exec', ast.PyCF_ONLY_AST, True)
<_ast.Module object at 0x7f35df872310>
>>> compile('return', '', 'exec', 0, True)
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "", line 1
SyntaxError: 'return' outside function
Is this intended behavior? It doesn't seem to be documented anywhere. |
|
Date |
User |
Action |
Args |
2017-06-12 12:37:36 | hniksic | set | recipients:
+ hniksic |
2017-06-12 12:37:36 | hniksic | set | messageid: <1497271056.08.0.482498543523.issue30637@psf.upfronthosting.co.za> |
2017-06-12 12:37:36 | hniksic | link | issue30637 messages |
2017-06-12 12:37:35 | hniksic | create | |
|