[ python-Bugs-1462485 ] StopIteration raised in body of 'with' statement suppressed

SourceForge.net noreply at sourceforge.net
Sat Apr 1 02:19:36 CEST 2006


Bugs item #1462485, was opened at 2006-04-01 00:17
Message generated for change (Comment added) made by tcdelaney
You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1462485&group_id=5470

Please note that this message will contain a full copy of the comment thread,
including the initial issue submission, for this request,
not just the latest update.
Category: Python Interpreter Core
Group: Python 2.5
Status: Open
Resolution: None
Priority: 5
Submitted By: Tim Delaney (tcdelaney)
Assigned to: Nobody/Anonymous (nobody)
Summary: StopIteration raised in body of 'with' statement suppressed

Initial Comment:
Given:

@contextmanager
def gen():
    print '__enter__'

    try:
        yield
    finally:
        print '__exit__'

with gen():
    raise StopIteration('body')


running the above results in:

__enter__
__exit__


I would have expected instead

__enter__
__exit__
Traceback (most recent call last):
  File "test25.py", line 53, in <module>
    raise StopIteration('body')
StopIteration: body


Note that doing:

with gen():
    raise GeneratorExit('body')

does the expected thing:

__enter__
__exit__
Traceback (most recent call last):
  File "test25.py", line 53, in <module>
    raise GeneratorExit('body')
GeneratorExit: body

----------------------------------------------------------------------

>Comment By: Tim Delaney (tcdelaney)
Date: 2006-04-01 00:19

Message:
Logged In: YES 
user_id=603121

Attached code and results.

----------------------------------------------------------------------

You can respond by visiting: 
https://sourceforge.net/tracker/?func=detail&atid=105470&aid=1462485&group_id=5470


More information about the Python-bugs-list mailing list