10000 [3.6] Clarify exception handler scope in contextlib (GH-1103) · python/cpython@bd1173f · GitHub
[go: up one dir, main page]

Skip to content

Commit bd1173f

Browse files
authored
[3.6] Clarify exception handler scope in contextlib (GH-1103)
Moved explicit raise from inside try to try...else. (cherry picked from commit 680e20b)
1 parent bc90250 commit bd1173f

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)
0