From 6cf2a3966e12af5f86781a5d20c0810953722811 Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 30 Sep 2016 14:20:55 +1000 Subject: [PATCH] tests/basics: Add further tests for nonlocal scoping and closures. --- tests/basics/scope.py | 22 ++++++++++++++++++++++ 1 file changed, 22 insertions(+) diff --git a/tests/basics/scope.py b/tests/basics/scope.py index 3aecc0b8d4..11704c482a 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()()())