Skip to content

Commit 94634b0

Browse files
committed
add unittest for testing for cases where nonlocal variables do not end up in the freevars of the function
1 parent 9fb8a9a commit 94634b0

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

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

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -930,3 +930,18 @@ class D(B, C):
930930
locs = list(A.locs.keys())
931931
for k in ["__module__", "__qualname__", "ranges", "B", "C", "locs", "D"]:
932932
assert k in locs, locs
933+
934+
935+
def test_free_var_with_nonlocals():
936+
def outer():
937+
var = None
938+
939+
def toInternal(obj):
940+
nonlocal var
941+
x = 10
942+
943+
return toInternal
944+
fnc = outer()
945+
c = fnc.__code__
946+
assert c.co_freevars == ('var',)
947+
assert c.co_cellvars == tuple()

0 commit comments

Comments
 (0)