Remove long suffix "L" on ints in bytecode for > 3.0

This commit is contained in:
rocky
2020-01-08 11:54:45 -05:00
parent 13d9bcaaa9
commit a98bc444f7
3 changed files with 18 additions and 9 deletions

View File

@@ -71,6 +71,7 @@ case $PYVERSION in
2.6) 2.6)
SKIP_TESTS=( SKIP_TESTS=(
[test_aepack.py]=1 # Fails on its own [test_aepack.py]=1 # Fails on its own
[test_doctest.py]=1 #
[test_dis.py]=1 # We change line numbers - duh! [test_dis.py]=1 # We change line numbers - duh!
[test_generators.py]=1 # Investigate [test_generators.py]=1 # Investigate
[test_grp.py]=1 # Long test - might work Control flow? [test_grp.py]=1 # Long test - might work Control flow?
@@ -239,6 +240,7 @@ case $PYVERSION in
3.6) 3.6)
SKIP_TESTS=( SKIP_TESTS=(
[test_aifc.py]=1 #
[test_atexit.py]=1 # [test_atexit.py]=1 #
[test_bdb.py]=1 # [test_bdb.py]=1 #
[test_buffer.py]=1 # parse error [test_buffer.py]=1 # parse error

View File

@@ -616,7 +616,7 @@ class SourceWalker(GenericASTTraversal, object):
for item in tup: for item in tup:
self.write(sep) self.write(sep)
l += len(sep) l += len(sep)
s = better_repr(item) s = better_repr(item, self.version)
l += len(s) l += len(s)
self.write(s) self.write(s)
sep = "," sep = ","
@@ -636,9 +636,9 @@ class SourceWalker(GenericASTTraversal, object):
data = node.pattr data = node.pattr
datatype = type(data) datatype = type(data)
if isinstance(data, float) : if isinstance(data, float) :
self.write(better_repr(data)) self.write(better_repr(data, self.version))
elif isinstance(data, complex): elif isinstance(data, complex):
self.write(better_repr(data)) self.write(better_repr(data, self.version))
elif isinstance(datatype, int) and data == minint: elif isinstance(datatype, int) and data == minint:
# convert to hex, since decimal representation # convert to hex, since decimal representation
# would result in 'LOAD_CONST; UNARY_NEGATIVE' # would result in 'LOAD_CONST; UNARY_NEGATIVE'

View File

@@ -3,12 +3,13 @@
# More could be done here though. # More could be done here though.
from math import copysign from math import copysign
from uncompyle6 import PYTHON_VERSION
def is_negative_zero(n): def is_negative_zero(n):
"""Returns true if n is -0.0""" """Returns true if n is -0.0"""
return n == 0.0 and copysign(1, n) == -1 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 """Work around Python's unorthogonal and unhelpful repr() for primitive float
and complex.""" and complex."""
if isinstance(v, float): if isinstance(v, float):
@@ -23,20 +24,26 @@ def better_repr(v):
return "-0.0" return "-0.0"
return repr(v) return repr(v)
elif isinstance(v, complex): elif isinstance(v, complex):
real = better_repr(v.real) real = better_repr(v.real, version)
imag = better_repr(v.imag) imag = better_repr(v.imag, version)
# FIXME: we could probably use repr() in most cases # FIXME: we could probably use repr() in most cases
# sort out when that's possible. # sort out when that's possible.
# The below is however round-tripable, and Python's repr() isn't. # The below is however round-tripable, and Python's repr() isn't.
return "complex(%s, %s)" % (real, imag) return "complex(%s, %s)" % (real, imag)
elif isinstance(v, tuple): elif isinstance(v, tuple):
if len(v) == 1: 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) 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): elif isinstance(v, list):
l = better_repr(v) l = better_repr(v)
if len(v) == 1: 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) return "[%s]" % ", ".join(better_repr(i) for i in v)
# TODO: elif deal with sets and dicts # TODO: elif deal with sets and dicts
else: else: