]> granicus.if.org Git - python/commitdiff
[3.6] Clarify exception handler scope in contextlib (GH-1103)
authorMariatta <Mariatta@users.noreply.github.com>
Thu, 13 Apr 2017 03:52:39 +0000 (20:52 -0700)
committerGitHub <noreply@github.com>
Thu, 13 Apr 2017 03:52:39 +0000 (20:52 -0700)
Moved explicit raise from inside try to try...else.
(cherry picked from commit 680e20beee8bbce9f857b8e7795009191f98b0ba)

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