Um, I thought I'd already checked this in.

Anyway, this is the changes to the with-statement
so that __exit__ must return a true value in order
for a pending exception to be ignored.
The PEP (343) is already updated.
This commit is contained in:
Guido van Rossum 2006-03-10 02:28:35 +00:00
parent 692cdbc5d6
commit f669436189
11 changed files with 61 additions and 106 deletions

View file

@ -30,8 +30,9 @@ class GeneratorContextManager(object):
else:
try:
self.gen.throw(type, value, traceback)
return True
except StopIteration:
pass
return True
def contextmanager(func):
@ -91,6 +92,7 @@ def nested(*contexts):
"""
exits = []
vars = []
exc = (None, None, None)
try:
try:
for context in contexts:
@ -102,17 +104,14 @@ def nested(*contexts):
yield vars
except:
exc = sys.exc_info()
else:
exc = (None, None, None)
finally:
while exits:
exit = exits.pop()
try:
exit(*exc)
if exit(*exc):
exc = (None, None, None)
except:
exc = sys.exc_info()
else:
exc = (None, None, None)
if exc != (None, None, None):
raise