Fix a bug in nested() - if one of the sub-context-managers swallows the
exception, it should not be propagated up. With unit tests.
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index 33d83a6..33c302d 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -91,7 +91,6 @@
"""
exits = []
vars = []
- exc = (None, None, None)
try:
try:
for context in contexts:
@@ -103,6 +102,8 @@
yield vars
except:
exc = sys.exc_info()
+ else:
+ exc = (None, None, None)
finally:
while exits:
exit = exits.pop()
@@ -110,6 +111,8 @@
exit(*exc)
except:
exc = sys.exc_info()
+ else:
+ exc = (None, None, None)
if exc != (None, None, None):
raise