From a98bc444f70bcd52190d259f116bc1c34d9e340d Mon Sep 17 00:00:00 2001 From: rocky Date: Wed, 8 Jan 2020 11:54:45 -0500 Subject: [PATCH] Remove long suffix "L" on ints in bytecode for > 3.0 --- test/stdlib/runtests.sh | 2 ++ uncompyle6/semantics/pysource.py | 6 +++--- uncompyle6/util.py | 19 +++++++++++++------ 3 files changed, 18 insertions(+), 9 deletions(-) diff --git a/test/stdlib/runtests.sh b/test/stdlib/runtests.sh index 38380cca..3e635a2b 100755 --- a/test/stdlib/runtests.sh +++ b/test/stdlib/runtests.sh @@ -71,6 +71,7 @@ case $PYVERSION in 2.6) SKIP_TESTS=( [test_aepack.py]=1 # Fails on its own + [test_doctest.py]=1 # [test_dis.py]=1 # We change line numbers - duh! [test_generators.py]=1 # Investigate [test_grp.py]=1 # Long test - might work Control flow? @@ -239,6 +240,7 @@ case $PYVERSION in 3.6) SKIP_TESTS=( + [test_aifc.py]=1 # [test_atexit.py]=1 # [test_bdb.py]=1 # [test_buffer.py]=1 # parse error diff --git a/uncompyle6/semantics/pysource.py b/uncompyle6/semantics/pysource.py index 400a140c..a7741f3b 100644 --- a/uncompyle6/semantics/pysource.py +++ b/uncompyle6/semantics/pysource.py @@ -616,7 +616,7 @@ class SourceWalker(GenericASTTraversal, object): for item in tup: self.write(sep) l += len(sep) - s = better_repr(item) + s = better_repr(item, self.version) l += len(s) self.write(s) sep = "," @@ -636,9 +636,9 @@ class SourceWalker(GenericASTTraversal, object): data = node.pattr datatype = type(data) if isinstance(data, float) : - self.write(better_repr(data)) + self.write(better_repr(data, self.version)) elif isinstance(data, complex): - self.write(better_repr(data)) + self.write(better_repr(data, self.version)) elif isinstance(datatype, int) and data == minint: # convert to hex, since decimal representation # would result in 'LOAD_CONST; UNARY_NEGATIVE' diff --git a/uncompyle6/util.py b/uncompyle6/util.py index 12a60175..0dd7c2c1 100644 --- a/uncompyle6/util.py +++ b/uncompyle6/util.py @@ -3,12 +3,13 @@ # More could be done here though. from math import copysign +from uncompyle6 import PYTHON_VERSION def is_negative_zero(n): """Returns true if n is -0.0""" return n == 0.0 and copysign(1, n) == -1 -def better_repr(v): +def better_repr(v, version): """Work around Python's unorthogonal and unhelpful repr() for primitive float and complex.""" if isinstance(v, float): @@ -23,20 +24,26 @@ def better_repr(v): return "-0.0" return repr(v) elif isinstance(v, complex): - real = better_repr(v.real) - imag = better_repr(v.imag) + real = better_repr(v.real, version) + imag = better_repr(v.imag, version) # FIXME: we could probably use repr() in most cases # sort out when that's possible. # The below is however round-tripable, and Python's repr() isn't. return "complex(%s, %s)" % (real, imag) elif isinstance(v, tuple): if len(v) == 1: - return "(%s,)" % better_repr(v[0]) - return "(%s)" % ", ".join(better_repr(i) for i in v) + return "(%s,)" % better_repr(v[0], version) + return "(%s)" % ", ".join(better_repr(i, version) for i in v) + elif PYTHON_VERSION < 3.0 and isinstance(v, long): + s = repr(v) + if version >= 3.0 and s[-1] == "L": + return s[:-1] + else: + return s elif isinstance(v, list): l = better_repr(v) if len(v) == 1: - return "[%s,]" % better_repr(v[0]) + return "[%s,]" % better_repr(v[0], version) return "[%s]" % ", ".join(better_repr(i) for i in v) # TODO: elif deal with sets and dicts else: