Skip to content

Commit e335f24

Browse files
committed
add test for some cell confusion problems
1 parent f8161d4 commit e335f24

File tree

1 file changed

+44
-1
lines changed

1 file changed

+44
-1
lines changed

graalpython/com.oracle.graal.python.test/src/tests/test_generators.py

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Copyright (c) 2018, Oracle and/or its affiliates.
1+
# Copyright (c) 2018, 2019 Oracle and/or its affiliates.
22
# Copyright (C) 1996-2017 Python Software Foundation
33
#
44
# Licensed under the PYTHON SOFTWARE FOUNDATION LICENSE VERSION 2
@@ -178,3 +178,46 @@ def func(*args):
178178
gen = (x for x in range(10))
179179
assert func(*lst) == set(lst)
180180
assert func(*gen) == set(lst)
181+
182+
183+
def test_generator_cell_confusion():
184+
# tfel: this demonstrates various errors we can get when we get confused
185+
# about the generator scopes and their parents for eager iterator
186+
# evaluation. In fact, all of these should work
187+
def unbound_local_l2():
188+
l1 = []
189+
l2 = []
190+
return [
191+
link for link in (
192+
(url for url in l1),
193+
(url for url in l2)
194+
)
195+
]
196+
197+
assert len(unbound_local_l2()) == 2
198+
199+
def assertion_error_getting_closure_from_locals():
200+
l1 = []
201+
l2 = []
202+
l3 = []
203+
return [
204+
link for link in (
205+
(url for url in l1),
206+
(url for url in l2),
207+
(url for url in l3),
208+
)
209+
]
210+
211+
assert len(assertion_error_getting_closure_from_locals()) == 3
212+
213+
def illegal_state_expected_cell_got_list():
214+
l11, l1 = [], []
215+
l22, l2 = [], []
216+
return [
217+
link for link in (
218+
(url for url in l1),
219+
(url for url in l2),
220+
)
221+
]
222+
223+
assert len(illegal_state_expected_cell_got_list()) == 2

0 commit comments

Comments
 (0)