From a9f068726fb4cf3693bd70b4b98bd0deaba45443 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Wed, 1 Mar 2006 17:10:01 +0000 Subject: Fix a bug in nested() - if one of the sub-context-managers swallows the exception, it should not be propagated up. With unit tests. --- Lib/contextlib.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) (limited to 'Lib/contextlib.py') diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 33d83a6e14..33c302dd96 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -91,7 +91,6 @@ def nested(*contexts): """ exits = [] vars = [] - exc = (None, None, None) try: try: for context in contexts: @@ -103,6 +102,8 @@ def nested(*contexts): yield vars except: exc = sys.exc_info() + else: + exc = (None, None, None) finally: while exits: exit = exits.pop() @@ -110,6 +111,8 @@ def nested(*contexts): exit(*exc) except: exc = sys.exc_info() + else: + exc = (None, None, None) if exc != (None, None, None): raise -- cgit v1.2.1