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: 7 Submitted By: Tim Delaney (tcdelaney) Assigned to: Nick Coghlan (ncoghlan) 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-02 02:42 Message: Logged In: YES user_id=603121 Attached diffs to test_with.py which adds tests for raising StopIteration (and GeneratorExit) from the body of a with-statement where the context manager is either a generator, or a class instance. I think the correct behaviour is to return False from GeneratorContextManager.__exit__ if the thrown exception is a StopIteration, and the exact same instance is raised from self.gen.throw(). Diffs for this also attached. ---------------------------------------------------------------------- Comment By: Georg Brandl (gbrandl) Date: 2006-04-01 07:02 Message: Logged In: YES user_id=849994 Nick, I can't tell whether this is intentional without rereading the specs. Can you? ---------------------------------------------------------------------- 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 _______________________________________________ Python-bugs-list mailing list Unsubscribe: http://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com