replace unneeded eval() call and support negative versionCodes

This commit is contained in:
Hans-Christoph Steiner 2018-08-29 16:07:02 +02:00
parent f0d27e1fa5
commit 4503e7a92a
2 changed files with 23 additions and 6 deletions

View file

@ -3275,8 +3275,12 @@ def get_git_describe_link():
def calculate_math_string(expr):
ops = {ast.Add: operator.add, ast.Sub: operator.sub,
ast.Mult: operator.mul}
ops = {
ast.Add: operator.add,
ast.Mult: operator.mul,
ast.Sub: operator.sub,
ast.USub: operator.neg,
}
def execute_ast(node):
if isinstance(node, ast.Num): # <number>
@ -3285,7 +3289,7 @@ def calculate_math_string(expr):
return ops[type(node.op)](execute_ast(node.left),
execute_ast(node.right))
elif isinstance(node, ast.UnaryOp): # <operator> <operand> e.g., -1
return ops[type(node.op)](eval(node.operand))
return ops[type(node.op)](ast.literal_eval(node.operand))
else:
raise SyntaxError(node)