summaryrefslogtreecommitdiffstats
path: root/Lib/contextlib.py
diff options
context:
space:
mode:
authorGuido van Rossum <guido@python.org>2006-03-10 02:28:35 (GMT)
committerGuido van Rossum <guido@python.org>2006-03-10 02:28:35 (GMT)
commitf669436189dd44a841caa9ab1ad97a3f7662bf58 (patch)
tree1a717975d09d4867e8807710a36a6c2999afdb7e /Lib/contextlib.py
parent692cdbc5d648da5239b5caececc954960aa024e9 (diff)
downloadcpython-f669436189dd44a841caa9ab1ad97a3f7662bf58.zip
cpython-f669436189dd44a841caa9ab1ad97a3f7662bf58.tar.gz
cpython-f669436189dd44a841caa9ab1ad97a3f7662bf58.tar.bz2
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.
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r--Lib/contextlib.py11
1 files changed, 5 insertions, 6 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index 33c302d..0a5d608 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -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