Commit 680e20be authored by amosonn's avatar amosonn Committed by Nick Coghlan

Clarify exception handler scope in contextlib

Moved explicit raise from inside try to try...else.
parent eca52296
...@@ -98,7 +98,6 @@ class _GeneratorContextManager(ContextDecorator, AbstractContextManager): ...@@ -98,7 +98,6 @@ class _GeneratorContextManager(ContextDecorator, AbstractContextManager):
value = type() value = type()
try: try:
self.gen.throw(type, value, traceback) self.gen.throw(type, value, traceback)
raise RuntimeError("generator didn't stop after throw()")
except StopIteration as exc: except StopIteration as exc:
# Suppress StopIteration *unless* it's the same exception that # Suppress StopIteration *unless* it's the same exception that
# was passed to throw(). This prevents a StopIteration # was passed to throw(). This prevents a StopIteration
...@@ -124,6 +123,8 @@ class _GeneratorContextManager(ContextDecorator, AbstractContextManager): ...@@ -124,6 +123,8 @@ class _GeneratorContextManager(ContextDecorator, AbstractContextManager):
# #
if sys.exc_info()[1] is not value: if sys.exc_info()[1] is not value:
raise raise
else:
raise RuntimeError("generator didn't stop after throw()")
def contextmanager(func): def contextmanager(func):
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment