Commit d9404c4b authored by Stefan Behnel's avatar Stefan Behnel

extend except-as test case

parent 69f163fb
...@@ -381,9 +381,36 @@ def except_as_raise_deletes_target(x, a): ...@@ -381,9 +381,36 @@ def except_as_raise_deletes_target(x, a):
except a as b: except a as b:
i = 2 i = 2
assert isinstance(b, a) assert isinstance(b, a)
print(b) # raises NameError if except clause was executed print(b) # raises UnboundLocalError if except clause was executed
return i return i
def except_as_deletes_target_in_gen(x, a):
"""
>>> list(except_as_deletes_target_in_gen(None, TypeError))
[(1, 1), (2, 1), (5, 1)]
>>> list(except_as_deletes_target_in_gen(TypeError('test'), TypeError))
[(1, 1), 3, 6]
>>> list(except_as_deletes_target_in_gen(ValueError('test'), TypeError))
[(1, 1), (4, 1), (5, 1)]
"""
b = 1
try:
i = 1
yield (1, b)
if x:
raise x
yield (2, b)
except a as b:
i = 2
assert isinstance(b, a)
yield 3
except:
yield (4, b)
try:
yield (5, b)
except UnboundLocalError:
yield 6
def complete_except_as_no_raise(a, b): def complete_except_as_no_raise(a, b):
""" """
>>> complete_except_as_no_raise(TypeError, ValueError) >>> complete_except_as_no_raise(TypeError, ValueError)
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment