test case for ticket #598: scoped list comp in function closure
authorStefan Behnel <scoder@users.berlios.de>
Wed, 24 Nov 2010 22:00:04 +0000 (23:00 +0100)
committerStefan Behnel <scoder@users.berlios.de>
Wed, 24 Nov 2010 22:00:04 +0000 (23:00 +0100)
tests/bugs.txt
tests/run/list_comp_in_closure_T598.pyx [new file with mode: 0644]

index 2f5cba2910ed30b7465ca85a8cde8ea0ad4b3ee7..32dee7355a2d7f84703afa2fb1a4855f808390d0 100644 (file)
@@ -17,6 +17,7 @@ function_as_method_T494
 closure_inside_cdef_T554
 ipow_crash_T562
 pure_mode_cmethod_inheritance_T583
+list_comp_in_closure_T598
 
 # CPython regression tests that don't current work:
 pyregr.test_threadsignals
diff --git a/tests/run/list_comp_in_closure_T598.pyx b/tests/run/list_comp_in_closure_T598.pyx
new file mode 100644 (file)
index 0000000..5246df2
--- /dev/null
@@ -0,0 +1,27 @@
+# cython: language_level=3
+
+def list_comp_in_closure():
+    """
+    >>> list_comp_in_closure()
+    [0, 4, 8]
+    """
+    x = 'abc'
+    def f():
+        return x
+    result = [x*2 for x in range(5) if x % 2 == 0]
+    assert x == 'abc' # don't leak in Py3 code
+    assert f() == 'abc' # don't leak in Py3 code
+    return result
+
+def genexpr_in_closure():
+    """
+    >>> genexpr_in_closure()
+    [0, 4, 8]
+    """
+    x = 'abc'
+    def f():
+        return x
+    result = list( x*2 for x in range(5) if x % 2 == 0 )
+    assert x == 'abc' # don't leak in Py3 code
+    assert f() == 'abc' # don't leak in Py3 code
+    return result