Do not pretend expression is filename in compile() Python built-in call (#73113)

When calling compile(), the filename argument should be either a real file
name or a string. According to Python docs, suggested one is '<string>'.
 Keep the current behaviour (encapsulate the actual expression), 
but enclose it into angle brackets.

Signed-off-by: Oldřich Jedlička <oldium.pro@gmail.com>
pull/73295/head
Oldřich Jedlička 4 years ago committed by GitHub
parent e8d4b62b41
commit ec55a221f6
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -0,0 +1,4 @@
bugfixes:
- Pass expression in angle-bracket notation as filename argument to a
``compile()`` built-in function, so that Python debuggers do not try to
parse it as filename.

@ -140,7 +140,7 @@ def safe_eval(expr, locals=None, include_exceptions=False):
try:
parsed_tree = ast.parse(expr, mode='eval')
cnv.visit(parsed_tree)
compiled = compile(parsed_tree, to_native(expr), 'eval')
compiled = compile(parsed_tree, '<expr %s>' % to_native(expr), 'eval')
# Note: passing our own globals and locals here constrains what
# callables (and other identifiers) are recognized. this is in
# addition to the filtering of builtins done in CleansingNodeVisitor

Loading…
Cancel
Save