Skip to content

Commit

Permalink
Clarify exception handler scope in contextlib
Browse files Browse the repository at this point in the history
Moved explicit raise from inside try to try...else.
  • Loading branch information
amosonn authored and ncoghlan committed Mar 1, 2017
1 parent eca5229 commit 680e20b
Showing 1 changed file with 2 additions and 1 deletion.
3 changes: 2 additions & 1 deletion Lib/contextlib.py
Expand Up @@ -98,7 +98,6 @@ def __exit__(self, type, value, traceback):
value = type()
try:
self.gen.throw(type, value, traceback)
raise RuntimeError("generator didn't stop after throw()")
except StopIteration as exc:
# Suppress StopIteration *unless* it's the same exception that
# was passed to throw(). This prevents a StopIteration
Expand All @@ -124,6 +123,8 @@ def __exit__(self, type, value, traceback):
#
if sys.exc_info()[1] is not value:
raise
else:
raise RuntimeError("generator didn't stop after throw()")


def contextmanager(func):
Expand Down

0 comments on commit 680e20b

Please sign in to comment.