From: Stefan Behnel Date: Wed, 24 Nov 2010 22:00:04 +0000 (+0100) Subject: test case for ticket #598: scoped list comp in function closure X-Git-Tag: 0.14.alpha0~92 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=a6b0f4059f42d92e3e43ca788a1452461b6b7ed7;p=cython.git test case for ticket #598: scoped list comp in function closure --- diff --git a/tests/bugs.txt b/tests/bugs.txt index 2f5cba29..32dee735 100644 --- a/tests/bugs.txt +++ b/tests/bugs.txt @@ -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 index 00000000..5246df27 --- /dev/null +++ b/tests/run/list_comp_in_closure_T598.pyx @@ -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