From: Stefan Behnel Date: Wed, 6 Feb 2008 08:47:28 +0000 (+0100) Subject: test case for tuple unpacking of a list comprehension X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a21ec3d462dff650bfac629ee662f2a998e3bb10;p=cython.git test case for tuple unpacking of a list comprehension --- diff --git a/tests/run/unpacklistcomp.pyx b/tests/run/unpacklistcomp.pyx new file mode 100644 index 00000000..c6a2dde7 --- /dev/null +++ b/tests/run/unpacklistcomp.pyx @@ -0,0 +1,31 @@ +__doc__ = """ + >>> unpack_normal([1,2]) + (1, 2) + >>> unpack_normal([1,2,3]) + Traceback (most recent call last): + ValueError: too many values to unpack + + >>> unpack_comp([1,2]) + (1, 2) + >>> unpack_comp([1,2,3]) + Traceback (most recent call last): + ValueError: too many values to unpack + + >>> unpack_expr([1,2]) + (1, 2) + >>> unpack_expr([1,2,3]) + Traceback (most recent call last): + ValueError: too many values to unpack +""" + +def unpack_normal(l): + a,b = l + return a,b + +def unpack_comp(l): + a,b = [ n for n in l ] + return a,b + +def unpack_expr(l): + a,b = [ n*n for n in l ] + return a,b