mirror of
https://github.com/python/cpython.git
synced 2025-08-22 17:55:18 +00:00
Fix a bug in nested() - if one of the sub-context-managers swallows the
exception, it should not be propagated up. With unit tests.
This commit is contained in:
parent
6db0e00d57
commit
a9f068726f
2 changed files with 58 additions and 1 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue