From f669436189dd44a841caa9ab1ad97a3f7662bf58 Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Fri, 10 Mar 2006 02:28:35 +0000 Subject: 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. --- Lib/contextlib.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) (limited to 'Lib/contextlib.py') diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 33c302dd96..0a5d608503 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 -- cgit v1.2.1