mirror of
https://github.com/rocky/python-uncompyle6.git
synced 2024-11-23 05:00:07 +00:00
Fixes #278
This commit is contained in:
parent
3f9a862277
commit
2e01f42f65
BIN
test/bytecode_3.5_run/02_build_list_unpack.pyc
Normal file
BIN
test/bytecode_3.5_run/02_build_list_unpack.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.6_run/02_build_list_unpack.pyc
Normal file
BIN
test/bytecode_3.6_run/02_build_list_unpack.pyc
Normal file
Binary file not shown.
BIN
test/bytecode_3.7_run/02_build_list_unpack.pyc
Normal file
BIN
test/bytecode_3.7_run/02_build_list_unpack.pyc
Normal file
Binary file not shown.
17
test/simple_source/bug35/02_build_list_unpack.py
Normal file
17
test/simple_source/bug35/02_build_list_unpack.py
Normal file
@ -0,0 +1,17 @@
|
||||
a = 5
|
||||
x = [1, 2, 3]
|
||||
i = [(a,), x]
|
||||
j = [a, *x]
|
||||
|
||||
def f1(a):
|
||||
return a[0], a[1]
|
||||
|
||||
def f2(b):
|
||||
return len(b), b[0]+5, b[2]
|
||||
|
||||
def f3(x, y):
|
||||
return [1, *x, y]
|
||||
|
||||
assert f1(i) == ((5,), x)
|
||||
assert f2(j) == (4, 10, 2)
|
||||
assert f3(x, a) == [1, 1, 2, 3, 5]
|
@ -56,7 +56,65 @@ def customize_for_version35(self, version):
|
||||
node.kind == 'async_call'
|
||||
self.prune()
|
||||
self.n_async_call = async_call
|
||||
self.n_build_list_unpack = self.n_list
|
||||
|
||||
def n_build_list_unpack(node):
|
||||
"""
|
||||
prettyprint a list or tuple
|
||||
"""
|
||||
p = self.prec
|
||||
self.prec = 100
|
||||
lastnode = node.pop()
|
||||
lastnodetype = lastnode.kind
|
||||
|
||||
# If this build list is inside a CALL_FUNCTION_VAR,
|
||||
# then the first * has already been printed.
|
||||
# Until I have a better way to check for CALL_FUNCTION_VAR,
|
||||
# will assume that if the text ends in *.
|
||||
last_was_star = self.f.getvalue().endswith("*")
|
||||
|
||||
if lastnodetype.startswith("BUILD_LIST"):
|
||||
self.write("[")
|
||||
endchar = "]"
|
||||
|
||||
flat_elems = flatten_list(node)
|
||||
|
||||
self.indent_more(INDENT_PER_LEVEL)
|
||||
sep = ""
|
||||
for elem in flat_elems:
|
||||
if elem in ("ROT_THREE", "EXTENDED_ARG"):
|
||||
continue
|
||||
assert elem == "expr"
|
||||
line_number = self.line_number
|
||||
use_star = True
|
||||
value = self.traverse(elem)
|
||||
if value.startswith("("):
|
||||
assert value.endswith(")")
|
||||
use_star = False
|
||||
value = value[1:-1].rstrip(" ") # Remove starting '(' and trailing ')' and additional spaces
|
||||
if value == "":
|
||||
pass
|
||||
else:
|
||||
if value.endswith(","): # if args has only one item
|
||||
value = value[:-1]
|
||||
if line_number != self.line_number:
|
||||
sep += "\n" + self.indent + INDENT_PER_LEVEL[:-1]
|
||||
else:
|
||||
if sep != "":
|
||||
sep += " "
|
||||
if not last_was_star and use_star:
|
||||
sep += "*"
|
||||
pass
|
||||
else:
|
||||
last_was_star = False
|
||||
self.write(sep, value)
|
||||
sep = ","
|
||||
self.write(endchar)
|
||||
self.indent_less(INDENT_PER_LEVEL)
|
||||
|
||||
self.prec = p
|
||||
self.prune()
|
||||
return
|
||||
self.n_build_list_unpack = n_build_list_unpack
|
||||
|
||||
def n_call(node):
|
||||
mapping = self._get_mapping(node)
|
||||
|
@ -1816,19 +1816,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
lastnode = node.pop()
|
||||
lastnodetype = lastnode.kind
|
||||
|
||||
# If this build list is inside a CALL_FUNCTION_VAR,
|
||||
# then the first * has already been printed.
|
||||
# Until I have a better way to check for CALL_FUNCTION_VAR,
|
||||
# will assume that if the text ends in *.
|
||||
last_was_star = self.f.getvalue().endswith("*")
|
||||
|
||||
if lastnodetype.endswith("UNPACK"):
|
||||
# FIXME: need to handle range of BUILD_LIST_UNPACK
|
||||
have_star = True
|
||||
# endchar = ''
|
||||
else:
|
||||
have_star = False
|
||||
|
||||
if lastnodetype.startswith("BUILD_LIST"):
|
||||
self.write("[")
|
||||
endchar = "]"
|
||||
@ -1879,13 +1866,6 @@ class SourceWalker(GenericASTTraversal, object):
|
||||
else:
|
||||
if sep != "":
|
||||
sep += " "
|
||||
if not last_was_star:
|
||||
if have_star:
|
||||
sep += "*"
|
||||
pass
|
||||
pass
|
||||
else:
|
||||
last_was_star = False
|
||||
self.write(sep, value)
|
||||
sep = ","
|
||||
if lastnode.attr == 1 and lastnodetype.startswith("BUILD_TUPLE"):
|
||||
|
Loading…
Reference in New Issue
Block a user