summaryrefslogtreecommitdiff
path: root/Lib/contextlib.py
diff options
context:
space:
mode:
authorPhillip J. Eby <pje@telecommunity.com>2006-03-25 00:28:24 +0000
committerPhillip J. Eby <pje@telecommunity.com>2006-03-25 00:28:24 +0000
commit6edd2586082f62a5ac61af5acab77b63919faa47 (patch)
tree183890c03fa62ea02b86afbcca1273427d03f72e /Lib/contextlib.py
parentbee071221419795d707a15286e08424d141a6ca6 (diff)
downloadcpython-git-6edd2586082f62a5ac61af5acab77b63919faa47.tar.gz
Fix a problem with @contextmanager not detecting a broken generator
that yields after a throw(). Make @contextmanager not reraise exceptions, but return a false value in that case instead. Add test cases for both behaviors.
Diffstat (limited to 'Lib/contextlib.py')
-rw-r--r--Lib/contextlib.py5
1 files changed, 4 insertions, 1 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py
index 0a5d608503..282fc51004 100644
--- a/Lib/contextlib.py
+++ b/Lib/contextlib.py
@@ -30,9 +30,12 @@ class GeneratorContextManager(object):
else:
try:
self.gen.throw(type, value, traceback)
- return True
+ raise RuntimeError("generator didn't stop after throw()")
except StopIteration:
return True
+ except:
+ if sys.exc_info()[1] is not value:
+ raise
def contextmanager(func):