Skip to content

Commit ccc7bb4

Browse files
committed
More extensive comment on __exit__ handling, per Guido's request.
1 parent e33901e commit ccc7bb4

1 file changed

Lines changed: 7 additions & 0 deletions

File tree

Lib/contextlib.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,13 @@ def __exit__(self, type, value, traceback):
3434
except StopIteration:
3535
return True
3636
except:
37+
# only re-raise if it's *not* the exception that was
38+
# passed to throw(), because __exit__() must not raise
39+
# an exception unless __exit__() itself failed. But throw()
40+
# has to raise the exception to signal propagation, so this
41+
# fixes the impedance mismatch between the throw() protocol
42+
# and the __exit__() protocol.
43+
#
3744
if sys.exc_info()[1] is not value:
3845
raise
3946

0 commit comments

Comments
 (0)