[Python-Dev] SF #1462485 - StopIteration raised in body of 'with' statement suppressed (original) (raw)
Guido van Rossum guido at python.org
Mon Apr 3 17:41:43 CEST 2006
- Previous message: [Python-Dev] SF #1462485 - StopIteration raised in body of 'with' statement suppressed
- Next message: [Python-Dev] SF #1462700 - Errors in PCbuild
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
On 4/2/06, Delaney, Timothy (Tim) <tdelaney at avaya.com> wrote:
Given:
@contextmanager def gen(): print 'enter' yield print 'exit' with gen(): raise StopIteration('body') I would expect to get the StopIteration exception raised. Instead it's suppressed by the @contextmanager decorator.
Right. I'm not sure how to fix this (but I think Phillip probably can).
I think we should only suppress the exception if it's not the exception passed into gen.throw() i.e. it's raised by the generator. Does this sound like the correct behaviour? I've attached tests and a fix implementing this to the bug report.
Cool.
I can't confirm right now (at work, need to install 2.5) but I'm also wondering what will happen if KeyboardInterrupt or SystemExit is raised from inside the generator when it's being closed via exit. I suspect a RuntimeError will be raised, whereas I think these should pass through.
I see no reason for this with the current code. Perhaps a previous version of contextlib.py had this problem?
-- --Guido van Rossum (home page: http://www.python.org/~guido/)
- Previous message: [Python-Dev] SF #1462485 - StopIteration raised in body of 'with' statement suppressed
- Next message: [Python-Dev] SF #1462700 - Errors in PCbuild
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]