Skip to content

Commit 9c49003

Browse files
committed
gh-156664: Split comprehension scope regression tests
1 parent 65116d5 commit 9c49003

1 file changed

Lines changed: 11 additions & 4 deletions

File tree

Lib/test/test_listcomps.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -757,23 +757,27 @@ def test_multiple_comprehension_name_reuse(self):
757757
self._check_in_scopes(code, {"x": 2, "y": [3]}, ns={"x": 3}, scopes=["class"])
758758
self._check_in_scopes(code, {"x": 2, "y": [2]}, ns={"x": 3}, scopes=["function", "module"])
759759

760+
def test_comprehension_name_reuse_with_free_variable(self):
760761
x = 3
761762

762-
def f():
763+
def sibling_comprehension():
763764
[x for x in [1]]
764765
return [x for _ in [1]]
765766

766-
self.assertEqual(f(), [3])
767+
self.assertEqual(sibling_comprehension(), [3])
767768

768-
def g():
769+
def nested_function():
769770
[x for x in [1]]
770771

771772
def inner():
772773
return x
773774

774775
return inner()
775776

776-
self.assertEqual(g(), 3)
777+
self.assertEqual(nested_function(), 3)
778+
779+
def test_comprehension_cell_and_free_variable(self):
780+
x = 3
777781

778782
def captured_then_sibling():
779783
funcs = [lambda: x for x in [1]]
@@ -797,6 +801,9 @@ def captured_then_generator_expression():
797801

798802
self.assertEqual(captured_then_generator_expression(), (1, [3]))
799803

804+
def test_comprehension_cell_exception_cleanup(self):
805+
x = 3
806+
800807
def raises_after_one():
801808
yield 1
802809
raise RuntimeError

0 commit comments

Comments
 (0)