test case for tuple unpacking of a list comprehension
authorStefan Behnel <scoder@users.berlios.de>
Wed, 6 Feb 2008 08:47:28 +0000 (09:47 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 6 Feb 2008 08:47:28 +0000 (09:47 +0100)
tests/run/unpacklistcomp.pyx [new file with mode: 0644]

diff --git a/tests/run/unpacklistcomp.pyx b/tests/run/unpacklistcomp.pyx
new file mode 100644 (file)
index 0000000..c6a2dde
--- /dev/null
@@ -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