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.

Author hniksic
Recipients hniksic
Date 2017-06-12.12:37:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1497271056.08.0.482498543523.issue30637@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2017-06-12 12:37:36hniksicsetrecipients: + hniksic
2017-06-12 12:37:36hniksicsetmessageid: <1497271056.08.0.482498543523.issue30637@psf.upfronthosting.co.za>
2017-06-12 12:37:36hniksiclinkissue30637 messages
2017-06-12 12:37:35hniksiccreate