From: Mariatta Date: Thu, 13 Apr 2017 03:52:39 +0000 (-0700) Subject: [3.6] Clarify exception handler scope in contextlib (GH-1103) X-Git-Tag: v3.6.2rc1~237 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=bd1173f202f5a3990063d980368e7ad1edc9b5b5;p=python [3.6] Clarify exception handler scope in contextlib (GH-1103) Moved explicit raise from inside try to try...else. (cherry picked from commit 680e20beee8bbce9f857b8e7795009191f98b0ba) --- diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 8421968525..e91cf460e5 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -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):