From a6b0f4059f42d92e3e43ca788a1452461b6b7ed7 Mon Sep 17 00:00:00 2001 From: Stefan Behnel Date: Wed, 24 Nov 2010 23:00:04 +0100 Subject: [PATCH] test case for ticket #598: scoped list comp in function closure --- tests/bugs.txt | 1 + tests/run/list_comp_in_closure_T598.pyx | 27 +++++++++++++++++++++++++ 2 files changed, 28 insertions(+) create mode 100644 tests/run/list_comp_in_closure_T598.pyx 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 -- 2.26.2