Skip to content

Commit d5bfd11

Browse files
committed
Correct construct nan
1 parent 14afa46 commit d5bfd11

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

src/python_minifier/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -223,7 +223,7 @@ def unparse(module):
223223
printer = ModulePrinter()
224224
printer(module)
225225

226-
print(printer.code)
226+
#print(printer.code)
227227

228228
try:
229229
minified_module = ast.parse(printer.code, 'python_minifier.unparse output')

src/python_minifier/transforms/constant_folding.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import ast
2+
import math
23

34
from python_minifier.expression_printer import ExpressionPrinter
45
from python_minifier.transforms.suite_transformer import SuiteTransformer
@@ -32,7 +33,10 @@ def visit_BinOp(self, node):
3233
except Exception as e:
3334
return node
3435

35-
if isinstance(value, str):
36+
if math.isnan(value):
37+
# There is no nan literal.
38+
new_node = ast.Call(func=ast.Name('float', ctx=ast.Load()), args=[ast.Str('nan')], keywords=[])
39+
elif isinstance(value, str):
3640
new_node = ast.Str(s=value)
3741
elif isinstance(value, bytes):
3842
new_node = ast.Bytes(s=value)

0 commit comments

Comments
 (0)