diff options
| author | Damien George <damien.p.george@gmail.com> | 2016-09-30 14:20:55 +1000 |
|---|---|---|
| committer | Damien George <damien.p.george@gmail.com> | 2016-09-30 14:20:55 +1000 |
| commit | 6cf2a3966e12af5f86781a5d20c0810953722811 (patch) | |
| tree | f581dc11032ea1790482bb1e023a264205d5f015 /tests | |
| parent | 0d10517a45fc90e7da9fc527ccfe51ab10205548 (diff) | |
tests/basics: Add further tests for nonlocal scoping and closures.
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/basics/scope.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/tests/basics/scope.py b/tests/basics/scope.py index 3aecc0b8d..11704c482 100644 --- a/tests/basics/scope.py +++ b/tests/basics/scope.py @@ -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()()()) |
