]> granicus.if.org Git - python/commitdiff
Clarify exception handler scope in contextlib
authoramosonn <amosonn@gmail.com>
Wed, 1 Mar 2017 06:18:27 +0000 (07:18 +0100)
committerNick Coghlan <ncoghlan@gmail.com>
Wed, 1 Mar 2017 06:18:27 +0000 (16:18 +1000)
Moved explicit raise from inside try to try...else.

Lib/contextlib.py

index 8421968525947e5b3b1090cf1e130979670ffc81..e91cf460e53bfde9ea55665d15bbd161699d24a5 100644 (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):