mirror of
https://github.com/python/cpython.git
synced 2025-10-05 14:41:07 +00:00
[3.5] Clarify exception handler scope in contextlib (GH-1104)
Moved explicit raise from inside try to try...else.
(cherry picked from commit 680e20beee
)
This commit is contained in:
parent
f3972dd1c1
commit
c0f4240fac
1 changed files with 2 additions and 1 deletions
|
@ -75,7 +75,6 @@ class _GeneratorContextManager(ContextDecorator):
|
||||||
value = type()
|
value = type()
|
||||||
try:
|
try:
|
||||||
self.gen.throw(type, value, traceback)
|
self.gen.throw(type, value, traceback)
|
||||||
raise RuntimeError("generator didn't stop after throw()")
|
|
||||||
except StopIteration as exc:
|
except StopIteration as exc:
|
||||||
# Suppress StopIteration *unless* it's the same exception that
|
# Suppress StopIteration *unless* it's the same exception that
|
||||||
# was passed to throw(). This prevents a StopIteration
|
# was passed to throw(). This prevents a StopIteration
|
||||||
|
@ -101,6 +100,8 @@ class _GeneratorContextManager(ContextDecorator):
|
||||||
#
|
#
|
||||||
if sys.exc_info()[1] is not value:
|
if sys.exc_info()[1] is not value:
|
||||||
raise
|
raise
|
||||||
|
else:
|
||||||
|
raise RuntimeError("generator didn't stop after throw()")
|
||||||
|
|
||||||
|
|
||||||
def contextmanager(func):
|
def contextmanager(func):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue