File tree Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Expand file tree Collapse file tree 1 file changed +8
-8
lines changed Original file line number Diff line number Diff line change @@ -1097,13 +1097,13 @@ import ast
1097
1097
from ast import Num, BinOp, UnaryOp
1098
1098
import operator as op
1099
1099
1100
- operators = {ast.Add: op.add,
1101
- ast.Sub: op.sub,
1102
- ast.Mult: op.mul,
1103
- ast.Div: op.truediv,
1104
- ast.Pow: op.pow,
1105
- ast.BitXor: op.xor,
1106
- ast.USub: op.neg}
1100
+ legal_operators = {ast.Add: op.add,
1101
+ ast.Sub: op.sub,
1102
+ ast.Mult: op.mul,
1103
+ ast.Div: op.truediv,
1104
+ ast.Pow: op.pow,
1105
+ ast.BitXor: op.xor,
1106
+ ast.USub: op.neg}
1107
1107
1108
1108
def evaluate (expression ):
1109
1109
root = ast.parse(expression, mode = ' eval' )
@@ -1115,7 +1115,7 @@ def eval_node(node):
1115
1115
return node.n
1116
1116
if type_ not in [BinOp, UnaryOp]:
1117
1117
raise TypeError (node)
1118
- operator = operators [type (node.op)]
1118
+ operator = legal_operators [type (node.op)]
1119
1119
if type_ == BinOp:
1120
1120
left, right = eval_node(node.left), eval_node(node.right)
1121
1121
return operator(left, right)
You can’t perform that action at this time.
0 commit comments