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

Lib/contextlib.py

index 4a7bd079a7dbb8eba117ff6a0dcf962fa9a7a4a1..c0188952ad701ec6e286dd6c07c3de6df30e1f9e 100644 (file)
@@ -75,7 +75,6 @@ class _GeneratorContextManager(ContextDecorator):
                 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
@@ -101,6 +100,8 @@ class _GeneratorContextManager(ContextDecorator):
                 #
                 if sys.exc_info()[1] is not value:
                     raise
+            else:
+                raise RuntimeError("generator didn't stop after throw()")
 
 
 def contextmanager(func):