File tree Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Expand file tree Collapse file tree 1 file changed +20
-2
lines changed Original file line number Diff line number Diff line change 12
12
ast .Pow : op .pow ,
13
13
ast .BitXor : op .xor ,
14
14
ast .USub : op .neg ,
15
- ast .Mod : op .mod
15
+ ast .Mod : op .mod ,
16
+ ast .BitAnd : op .and_ ,
17
+ ast .BitOr : op .or_ ,
18
+ ast .Invert : op .invert ,
19
+ ast .And : op .and_ ,
16
20
}
17
21
18
22
# TODO: restructure args to provide more info, generate hint based on args to save duplication
52
56
"call" : lambda * args : random .choice (args ),
53
57
"hint" : "...numbers"
54
58
},
59
+ "sqrt" : {
60
+ "args" : (1 , 1 ),
61
+ "call" : lambda a : math .sqrt (a ),
62
+ "hint" : "number"
63
+ },
64
+ "int" : {
65
+ "args" : (1 , 1 ),
66
+ "call" : lambda a = None : int (a ),
67
+ "hint" : "number"
68
+ },
55
69
}
56
70
57
71
autocompleteWords = list ({
@@ -140,7 +154,11 @@ def eval_expr(node):
140
154
if isinstance (node , ast .Num ):
141
155
return node .n
142
156
elif isinstance (node , ast .BinOp ):
143
- return operators [type (node .op )](float (eval_expr (node .left )), float (eval_expr (node .right )))
157
+ l = eval_expr (node .left )
158
+ r = eval_expr (node .right )
159
+ l = l if isinstance (l , int ) else float (l )
160
+ r = r if isinstance (r , int ) else float (r )
161
+ return operators [type (node .op )](l , r )
144
162
elif isinstance (node , ast .UnaryOp ):
145
163
return operators [type (node .op )](eval_expr (node .operand ))
146
164
elif isinstance (node , ast .Attribute ):
You can’t perform that action at this time.
0 commit comments