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

pull/2441/merge
Damien George 2016-09-30 14:20:55 +10:00
rodzic 0d10517a45
commit 6cf2a3966e
1 zmienionych plików z 22 dodań i 0 usunięć

Wyświetl plik

@ -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()()())