From beec0d8ab0df2efdbfa81c2ebc1baf7f4a71bc48 Mon Sep 17 00:00:00 2001 From: amosonn Date: Fri, 24 Feb 2017 01:43:55 +0100 Subject: [PATCH] Update contextlib.py Moved raise from inside try to try..else. --- Lib/contextlib.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/Lib/contextlib.py b/Lib/contextlib.py index 8421968525947e..e91cf460e53bfd 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -98,7 +98,6 @@ def __exit__(self, type, value, traceback): 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 @@ def __exit__(self, type, value, traceback): # if sys.exc_info()[1] is not value: raise + else: + raise RuntimeError("generator didn't stop after throw()") def contextmanager(func):