Skip to content

Commit 680e20b

Browse files
amosonnncoghlan
authored andcommitted
Clarify exception handler scope in contextlib
Moved explicit raise from inside try to try...else.
1 parent eca5229 commit 680e20b

File tree

1 file changed

+2
-1
lines changed

1 file changed

+2
-1
lines changed

Lib/contextlib.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,6 @@ def __exit__(self, type, value, traceback):
9898
value = type()
9999
try:
100100
self.gen.throw(type, value, traceback)
101-
raise RuntimeError("generator didn't stop after throw()")
102101
except StopIteration as exc:
103102
# Suppress StopIteration *unless* it's the same exception that
104103
# was passed to throw(). This prevents a StopIteration
@@ -124,6 +123,8 @@ def __exit__(self, type, value, traceback):
124123
#
125124
if sys.exc_info()[1] is not value:
126125
raise
126+
else:
127+
raise RuntimeError("generator didn't stop after throw()")
127128

128129

129130
def contextmanager(func):

0 commit comments

Comments
 (0)