Commit a265ec1a authored by Stefan Behnel's avatar Stefan Behnel

fix bug 409: use cascaded assignments also for the complete rhs when...

fix bug 409: use cascaded assignments also for the complete rhs when optimising parallel assignments
parent af67b788
...@@ -928,6 +928,8 @@ def flatten_parallel_assignments(input, output): ...@@ -928,6 +928,8 @@ def flatten_parallel_assignments(input, output):
output.append(input) output.append(input)
return return
complete_assignments = [rhs]
rhs_size = len(rhs.args) rhs_size = len(rhs.args)
lhs_targets = [ [] for _ in range(rhs_size) ] lhs_targets = [ [] for _ in range(rhs_size) ]
starred_assignments = [] starred_assignments = []
...@@ -935,7 +937,7 @@ def flatten_parallel_assignments(input, output): ...@@ -935,7 +937,7 @@ def flatten_parallel_assignments(input, output):
if not lhs.is_sequence_constructor: if not lhs.is_sequence_constructor:
if lhs.is_starred: if lhs.is_starred:
error(lhs.pos, "starred assignment target must be in a list or tuple") error(lhs.pos, "starred assignment target must be in a list or tuple")
output.append([lhs,rhs]) complete_assignments.append(lhs)
continue continue
lhs_size = len(lhs.args) lhs_size = len(lhs.args)
starred_targets = sum([1 for expr in lhs.args if expr.is_starred]) starred_targets = sum([1 for expr in lhs.args if expr.is_starred])
...@@ -966,6 +968,9 @@ def flatten_parallel_assignments(input, output): ...@@ -966,6 +968,9 @@ def flatten_parallel_assignments(input, output):
for targets, expr in zip(lhs_targets, lhs.args): for targets, expr in zip(lhs_targets, lhs.args):
targets.append(expr) targets.append(expr)
if len(complete_assignments) > 1:
output.append(complete_assignments[::-1])
# recursively flatten partial assignments # recursively flatten partial assignments
for cascade, rhs in zip(lhs_targets, rhs.args): for cascade, rhs in zip(lhs_targets, rhs.args):
if cascade: if cascade:
......
...@@ -7,4 +7,3 @@ numpy_ValueError_T172 ...@@ -7,4 +7,3 @@ numpy_ValueError_T172
unsignedbehaviour_T184 unsignedbehaviour_T184
bad_c_struct_T252 bad_c_struct_T252
missing_baseclass_in_predecl_T262 missing_baseclass_in_predecl_T262
extended_unpacking_T409
__doc__ = """
>>> simple()
(1, 2, [1, 2], [1, 2])
>>> extended()
(1, (), 2, [1, 2], [1, 2])
"""
def simple(): def simple():
"""
>>> simple()
([1, 2], [1, 2])
"""
d = e = [1,2]
return d, e
def simple_parallel():
"""
>>> simple_parallel()
(1, 2, [1, 2], [1, 2])
"""
a, c = d = e = [1,2] a, c = d = e = [1,2]
return a, c, d, e return a, c, d, e
def extended(): def extended():
"""
>>> extended()
(1, [], 2, [1, 2], [1, 2])
"""
a, *b, c = d = e = [1,2] a, *b, c = d = e = [1,2]
return a, b, c, d, e return a, b, c, d, e
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment