From 8bae84768248e457b34cc61d3b8a67a2c8eb66ab Mon Sep 17 00:00:00 2001 From: Valentin Lorentz Date: Sat, 25 Feb 2017 11:31:52 +0100 Subject: [PATCH] Use ast.parse in 'eval' mode instead of 'exec'. This fixes compatibility with Python 3.7; but we should have been doing this since b8fe420ef35c63a85a92179b62adf4556f2d1a92. The incompatibility with Python 3.7 was introduced in https://github.com/python/cpython/commit/cb41b2766de646435743b6af7dd152751b54e73f See also: http://bugs.python.org/issue29646 --- src/utils/gen.py | 9 +-------- 1 file changed, 1 insertion(+), 8 deletions(-) diff --git a/src/utils/gen.py b/src/utils/gen.py index 2065b1b3e..005e27806 100644 --- a/src/utils/gen.py +++ b/src/utils/gen.py @@ -169,16 +169,9 @@ def safeEval(s, namespace={'True': True, 'False': False, 'None': None}): """Evaluates s, safely. Useful for turning strings into tuples/lists/etc. without unsafely using eval().""" try: - node = ast.parse(s) + node = ast.parse(s, mode='eval').body except SyntaxError as e: raise ValueError('Invalid string: %s.' % e) - nodes = ast.parse(s).body - if not nodes: - if node.__class__ is ast.Module: - return node.doc - else: - raise ValueError(format('Unsafe string: %q', s)) - node = nodes[0] def checkNode(node): if node.__class__ is ast.Expr: node = node.value