Commit f49d1f6f authored by Stefan Behnel's avatar Stefan Behnel

disable broken optimisation for except-as special case

parent 9ce870cd
...@@ -6093,14 +6093,10 @@ class ExceptClauseNode(Node): ...@@ -6093,14 +6093,10 @@ class ExceptClauseNode(Node):
if (not getattr(self.body, 'stats', True) if (not getattr(self.body, 'stats', True)
and self.excinfo_target is None and self.excinfo_target is None
and (self.target is None or self.is_except_as)): and self.target is None):
# most simple case: no exception variable, empty body (pass) # most simple case: no exception variable, empty body (pass)
# => reset the exception state, done # => reset the exception state, done
code.putln("PyErr_Restore(0,0,0);") code.putln("PyErr_Restore(0,0,0);")
if self.is_except_as and self.target:
# "except ... as x" deletes x after use
# target is known to be a NameNode
self.target.generate_deletion_code(code)
code.put_goto(end_label) code.put_goto(end_label)
code.putln("}") code.putln("}")
return return
......
...@@ -384,6 +384,22 @@ def except_as_raise_deletes_target(x, a): ...@@ -384,6 +384,22 @@ def except_as_raise_deletes_target(x, a):
print(b) # raises UnboundLocalError if except clause was executed print(b) # raises UnboundLocalError if except clause was executed
return i return i
def except_as_raise_with_empty_except(x, a):
"""
>>> except_as_raise_with_empty_except(None, TypeError)
>>> except_as_raise_with_empty_except(TypeError('test'), TypeError)
>>> except_as_raise_with_empty_except(ValueError('test'), TypeError)
Traceback (most recent call last):
ValueError: test
>>> except_as_raise_with_empty_except(None, TypeError)
"""
try:
if x:
raise x
b = 1
except a as b: # previously raised UnboundLocalError
pass
def except_as_deletes_target_in_gen(x, a): def except_as_deletes_target_in_gen(x, a):
""" """
>>> list(except_as_deletes_target_in_gen(None, TypeError)) >>> list(except_as_deletes_target_in_gen(None, TypeError))
......
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