result = list( x*2 for x in x if x % 2 == 0 )
assert x == (0,1,2,3,4,5)
return result
+
+@cython.test_assert_path_exists('//ComprehensionNode')
+@cython.test_fail_if_path_exists('//SimpleCallNode')
+def genexpr_iterable_in_closure():
+ """
+ >>> genexpr_iterable_in_closure()
+ [0, 4, 8]
+ """
+ x = 'abc'
+ def f():
+ return x
+ result = list( x*2 for x in x if x % 2 == 0 )
+ assert x == 'abc' # don't leak in Py3 code
+ assert f() == 'abc' # don't leak in Py3 code
+ return result
assert x == 'abc' # don't leak in Py3 code
assert f() == 'abc' # don't leak in Py3 code
return result
+
+def genexpr_scope_in_closure():
+ """
+ >>> genexpr_scope_in_closure()
+ [0, 4, 8]
+ """
+ i = 2
+ x = 'abc'
+ def f():
+ return i, x
+ result = list( x*i for x in range(5) if x % 2 == 0 )
+ assert x == 'abc' # don't leak in Py3 code
+ assert f() == 2,'abc' # don't leak in Py3 code
+ return result