From: Stefan Behnel Date: Fri, 23 Oct 2009 08:10:14 +0000 (+0200) Subject: fix bug 409: use cascaded assignments also for the complete rhs when optimising paral... X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a265ec1aa6ffc67db9b4f60482e2a4cb13c88425;p=cython.git fix bug 409: use cascaded assignments also for the complete rhs when optimising parallel assignments --- diff --git a/Cython/Compiler/Parsing.py b/Cython/Compiler/Parsing.py index 2f28af04..c163d35b 100644 --- a/Cython/Compiler/Parsing.py +++ b/Cython/Compiler/Parsing.py @@ -928,6 +928,8 @@ def flatten_parallel_assignments(input, output): output.append(input) return + complete_assignments = [rhs] + rhs_size = len(rhs.args) lhs_targets = [ [] for _ in range(rhs_size) ] starred_assignments = [] @@ -935,7 +937,7 @@ def flatten_parallel_assignments(input, output): if not lhs.is_sequence_constructor: if lhs.is_starred: error(lhs.pos, "starred assignment target must be in a list or tuple") - output.append([lhs,rhs]) + complete_assignments.append(lhs) continue lhs_size = len(lhs.args) starred_targets = sum([1 for expr in lhs.args if expr.is_starred]) @@ -966,6 +968,9 @@ def flatten_parallel_assignments(input, output): for targets, expr in zip(lhs_targets, lhs.args): targets.append(expr) + if len(complete_assignments) > 1: + output.append(complete_assignments[::-1]) + # recursively flatten partial assignments for cascade, rhs in zip(lhs_targets, rhs.args): if cascade: diff --git a/tests/bugs.txt b/tests/bugs.txt index 58205179..31d6ff3a 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -7,4 +7,3 @@ numpy_ValueError_T172 unsignedbehaviour_T184 bad_c_struct_T252 missing_baseclass_in_predecl_T262 -extended_unpacking_T409 diff --git a/tests/run/extended_unpacking_T409.pyx b/tests/run/extended_unpacking_T409.pyx index a58b84d4..65cf23e4 100644 --- a/tests/run/extended_unpacking_T409.pyx +++ b/tests/run/extended_unpacking_T409.pyx @@ -1,14 +1,24 @@ -__doc__ = """ - >>> simple() - (1, 2, [1, 2], [1, 2]) - >>> extended() - (1, (), 2, [1, 2], [1, 2]) -""" 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] return a, c, d, e def extended(): + """ + >>> extended() + (1, [], 2, [1, 2], [1, 2]) + """ a, *b, c = d = e = [1,2] return a, b, c, d, e