diff Lib/test/test_generators.py @ 58707:76cf60e2d005 legacy-trunk

normalize exceptions passed to the __exit__ method #7853 In Python 2.x, exceptions in finally blocks are not normalized. Since with statements are implemented using finally blocks, ceval.c had to be tweaked to distinguish between with finally blocks and normal ones. A test for the finalization of generators containing with statements was also added.
author Benjamin Peterson <benjamin@python.org>
date Fri, 05 Feb 2010 02:12:14 +0000
parents 913c9bf98d60
children df9f8feb7444
line wrap: on
line diff
--- a/Lib/test/test_generators.py	Fri Feb 05 01:53:27 2010 +0000
+++ b/Lib/test/test_generators.py	Fri Feb 05 02:12:14 2010 +0000
@@ -1700,6 +1700,17 @@
 >>> del g
 exiting
 
+>>> class context(object):
+...    def __enter__(self): pass
+...    def __exit__(self, *args): print 'exiting'
+>>> def f():
+...     with context():
+...          yield
+>>> g = f()
+>>> g.next()
+>>> del g
+exiting
+
 
 GeneratorExit is not caught by except Exception: