berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
803 stars 102 forks source link

Infinity numbers in constant tuples #166

Open isidentical opened 4 years ago

isidentical commented 4 years ago

Infinity numbers doesn't get handled in constant tuples, I'll prepare a patch tomorrow.

>>> my_constant = ast.Constant(value=(1, 2, 1e10000, "foo"), kind=None)
>>> astor.to_source(my_constant)
"(1, 2, inf, 'foo')\n"

Also i am curious about if it is OK to determine inf replacement by checking the largest value (in ast.unparse, it is handled like this: "1e" + repr(sys.float_info.max_10_exp + 1)) instead of hard coding 1e1000