Clarify exception handler scope in contextlib

Moved explicit raise from inside try to try...else.
This commit is contained in:
amosonn 2017-03-01 07:18:27 +01:00 committed by Nick Coghlan
parent eca52296da
commit 680e20beee
1 changed files with 2 additions and 1 deletions

View File

@ -98,7 +98,6 @@ class _GeneratorContextManager(ContextDecorator, AbstractContextManager):
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
@ -124,6 +123,8 @@ class _GeneratorContextManager(ContextDecorator, AbstractContextManager):
#
if sys.exc_info()[1] is not value:
raise
else:
raise RuntimeError("generator didn't stop after throw()")
def contextmanager(func):