diff options
author | Guido van Rossum <guido@python.org> | 2006-03-10 02:28:35 +0000 |
---|---|---|
committer | Guido van Rossum <guido@python.org> | 2006-03-10 02:28:35 +0000 |
commit | 95737a4c2708964d58d9335fb55dd016e2ec0b9d (patch) | |
tree | b751a0f79c9d181f00fff6aed5b58e0b838b43a8 /Lib/contextlib.py | |
parent | 5c78f048a13c032f08de75dd5e8c10c830d42ca9 (diff) | |
download | cpython-95737a4c2708964d58d9335fb55dd016e2ec0b9d.tar.gz |
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.py | 11 |
1 files changed, 5 insertions, 6 deletions
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 |