You've already forked python-uncompyle6
mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2025-08-03 16:59:52 +08:00
Handle inf, +inf, -nan, and nan constants
This commit is contained in:
BIN
test/bytecode_2.7/01_float.pyc
Normal file
BIN
test/bytecode_2.7/01_float.pyc
Normal file
Binary file not shown.
4
test/simple_source/expression/01_float.py
Normal file
4
test/simple_source/expression/01_float.py
Normal file
@@ -0,0 +1,4 @@
|
||||
a = 1e300 * 1e300 * 0
|
||||
b = -1e300 * 1e300 * 0
|
||||
c = 1e300 * 1e300
|
||||
d = -1e300 * 1e300
|
@@ -808,7 +808,12 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
|
||||
def n_LOAD_CONST(self, node):
|
||||
data = node.pattr; datatype = type(data)
|
||||
if isinstance(datatype, int) and data == minint:
|
||||
if isinstance(data, float) and str(data) in frozenset(['nan', '-nan', 'inf', '-inf']):
|
||||
# float values 'nan' and 'inf' are not directly representable in Python at least
|
||||
# before 3.5 and even there it is via a library constant.
|
||||
# So we will canonicalize their representation as float('nan') and float('inf')
|
||||
self.write("float('%s')" % data)
|
||||
elif isinstance(datatype, int) and data == minint:
|
||||
# convert to hex, since decimal representation
|
||||
# would result in 'LOAD_CONST; UNARY_NEGATIVE'
|
||||
# change:hG/2002-02-07: this was done for all negative integers
|
||||
|
Reference in New Issue
Block a user