Skip to content

Commit 4abe91c

Browse files
committed
Ignore div for now
1 parent bcaf96f commit 4abe91c

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

src/python_minifier/transforms/constant_folding.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,11 @@ def visit_BinOp(self, node):
2525
if not is_ast_node(node.right, (ast.Num, ast.Str, 'Bytes', 'NameConstant')):
2626
return node
2727

28+
if isinstance(node.op, ast.Div):
29+
# Folding div is subtle, since it can have different results in Python 2 and Python 3
30+
# Do this once target version options have been implemented
31+
return node
32+
2833
expression_printer = ExpressionPrinter()
2934

3035
try:
@@ -62,7 +67,9 @@ def visit_BinOp(self, node):
6267
# Result is longer than original expression
6368
return node
6469

65-
assert eval(folded_expression) == value
70+
globals = {'__builtins__': {}} # Completely empty globals
71+
locals = {}
72+
assert eval(folded_expression, globals, locals) == value
6673

6774
# Some complex number values are parsed as a BinOp
6875
# Make sure we represent our AST the same way so it roundtrips correctly

0 commit comments

Comments
 (0)