Skip to content

Commit c0f4240

Browse files
authored
[3.5] Clarify exception handler scope in contextlib (GH-1104)
Moved explicit raise from inside try to try...else. (cherry picked from commit 680e20b)
1 parent f3972dd commit c0f4240

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
@@ -75,7 +75,6 @@ def __exit__(self, type, value, traceback):
7575
value = type()
7676
try:
7777
self.gen.throw(type, value, traceback)
78-
raise RuntimeError("generator didn't stop after throw()")
7978
except StopIteration as exc:
8079
# Suppress StopIteration *unless* it's the same exception that
8180
# was passed to throw(). This prevents a StopIteration
@@ -101,6 +100,8 @@ def __exit__(self, type, value, traceback):
101100
#
102101
if sys.exc_info()[1] is not value:
103102
raise
103+
else:
104+
raise RuntimeError("generator didn't stop after throw()")
104105

105106

106107
def contextmanager(func):

0 commit comments

Comments
 (0)