mirror of
https://github.com/python/cpython.git
synced 2026-01-06 07:22:09 +00:00
Fix test 9 (caught by ?!ng)
Add tests for unbound locals (Nick Mathewson)
This commit is contained in:
parent
2524d699f5
commit
de6024872a
2 changed files with 31 additions and 1 deletions
|
|
@ -11,3 +11,4 @@ test_scope
|
|||
10. recursion
|
||||
11. unoptimized namespaces
|
||||
12. lambdas
|
||||
13. UnboundLocal
|
||||
|
|
|
|||
|
|
@ -154,7 +154,7 @@ def actual_global(self):
|
|||
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 @@ def g():
|
|||
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
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue