cython-devel

changeset 4006:b1f04712264b

test case for ticket #598: scoped list comp in function closure
author Stefan Behnel <scoder@users.berlios.de>
date Wed Nov 24 23:00:04 2010 +0100 (3 years ago)
parents 8f5e3310b54b
children 77361d6754c0
files tests/bugs.txt tests/run/list_comp_in_closure_T598.pyx
line diff
1.1 --- a/tests/bugs.txt Wed Nov 24 19:21:42 2010 +0100 1.2 +++ b/tests/bugs.txt Wed Nov 24 23:00:04 2010 +0100 1.3 @@ -17,6 +17,7 @@ 1.4 closure_inside_cdef_T554 1.5 ipow_crash_T562 1.6 pure_mode_cmethod_inheritance_T583 1.7 +list_comp_in_closure_T598 1.8 1.9 # CPython regression tests that don't current work: 1.10 pyregr.test_threadsignals
2.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 2.2 +++ b/tests/run/list_comp_in_closure_T598.pyx Wed Nov 24 23:00:04 2010 +0100 2.3 @@ -0,0 +1,27 @@ 2.4 +# cython: language_level=3 2.5 + 2.6 +def list_comp_in_closure(): 2.7 + """ 2.8 + >>> list_comp_in_closure() 2.9 + [0, 4, 8] 2.10 + """ 2.11 + x = 'abc' 2.12 + def f(): 2.13 + return x 2.14 + result = [x*2 for x in range(5) if x % 2 == 0] 2.15 + assert x == 'abc' # don't leak in Py3 code 2.16 + assert f() == 'abc' # don't leak in Py3 code 2.17 + return result 2.18 + 2.19 +def genexpr_in_closure(): 2.20 + """ 2.21 + >>> genexpr_in_closure() 2.22 + [0, 4, 8] 2.23 + """ 2.24 + x = 'abc' 2.25 + def f(): 2.26 + return x 2.27 + result = list( x*2 for x in range(5) if x % 2 == 0 ) 2.28 + assert x == 'abc' # don't leak in Py3 code 2.29 + assert f() == 'abc' # don't leak in Py3 code 2.30 + return result