From de6024872abe4fd95972036db63d0a57cf557f94 Mon Sep 17 00:00:00 2001 From: Jeremy Hylton Date: Mon, 5 Feb 2001 17:35:20 +0000 Subject: [PATCH] Fix test 9 (caught by ?!ng) Add tests for unbound locals (Nick Mathewson) --- Lib/test/output/test_scope | 1 + Lib/test/test_scope.py | 31 ++++++++++++++++++++++++++++++- 2 files changed, 31 insertions(+), 1 deletion(-) diff --git a/Lib/test/output/test_scope b/Lib/test/output/test_scope index 3ada943b351..17e5cb80fa9 100644 --- a/Lib/test/output/test_scope +++ b/Lib/test/output/test_scope @@ -11,3 +11,4 @@ test_scope 10. recursion 11. unoptimized namespaces 12. lambdas +13. UnboundLocal diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 8be3f6185f8..57c0dcb269c 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -154,7 +154,7 @@ class Test: def str(self): return str(self) -t = test() +t = Test() verify(t.test() == "var") verify(t.method_and_var() == "method") verify(t.actual_global() == "global") @@ -247,3 +247,32 @@ f8 = lambda x, y, z: lambda a, b, c: lambda : z * (b + y) g = f8(1, 2, 3) h = g(2, 4, 6) verify(h() == 18) + +print "13. UnboundLocal" + +def errorInOuter(): + print y + def inner(): + return y + y = 1 + +def errorInInner(): + def inner(): + return y + inner() + y = 1 + +try: + errorInOuter() +except UnboundLocalError: + pass +else: + raise TestFailed + +try: + errorInInner() +except UnboundLocalError: + pass +else: + raise TestFailed +