From a21ec3d462dff650bfac629ee662f2a998e3bb10 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 6 Feb 2008 09:47:28 +0100 Subject: [PATCH] test case for tuple unpacking of a list comprehension --- tests/run/unpacklistcomp.pyx | 31 +++++++++++++++++++++++++++++++ 1 file changed, 31 insertions(+) create mode 100644 tests/run/unpacklistcomp.pyx 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 -- 2.26.2