Skip to content

Commit d9297ac

Browse files
committed
Add test case
1 parent cd1ae5f commit d9297ac

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

tests/expressions/test_interpreter_coverage6.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1598,6 +1598,21 @@ def inner():
15981598
interpreter.execute(parser.parse(code))
15991599
assert interpreter.local_env["result"] == [[3, 4], [4, 5]]
16001600

1601+
# Test comprehension with nonlocal variables
1602+
code = """
1603+
def outer():
1604+
count = 0
1605+
def inner():
1606+
nonlocal count
1607+
result = [count := count + i for i in range(3)]
1608+
return result, count
1609+
return inner()
1610+
1611+
result = outer()
1612+
"""
1613+
interpreter.execute(parser.parse(code))
1614+
assert interpreter.local_env["result"] == ([0, 1, 3], 3)
1615+
16011616

16021617
def test_scope_context_with_saved_env():
16031618
"""Test scope context with saved environment in detail.

0 commit comments

Comments
 (0)