tests/basics: Add further tests for nonlocal scoping and closures.

This commit is contained in:
Damien George 2016-09-30 14:20:55 +10:00
parent 0d10517a45
commit 6cf2a3966e
1 changed files with 22 additions and 0 deletions

View File

@ -19,3 +19,25 @@ def f():
g()
return a
print(f())
# nonlocal at inner-inner level (h)
def f():
x = 1
def g():
def h():
nonlocal x
return x
return h
return g
print(f()()())
# nonlocal declared at outer level (g), and referenced by inner level (h)
def f():
x = 1
def g():
nonlocal x
def h():
return x
return h
return g
print(f()()())