mirror of
https://github.com/python/cpython.git
synced 2025-08-27 20:25:18 +00:00
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.
This commit is contained in:
parent
692cdbc5d6
commit
f669436189
11 changed files with 61 additions and 106 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue