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.
This commit is contained in:
Phillip J. Eby 2006-03-25 00:28:24 +00:00
parent bee0712214
commit 6edd258608
2 changed files with 26 additions and 1 deletions

View file

@ -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):