mirror of
https://github.com/python/cpython.git
synced 2025-08-04 17:08:35 +00:00
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.
This commit is contained in:
parent
4a7ff1d80a
commit
565d78586b
5 changed files with 26 additions and 6 deletions
|
@ -1700,6 +1700,17 @@ And finalization:
|
|||
>>> 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:
|
||||
|
||||
|
|
|
@ -361,7 +361,6 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin):
|
|||
self.assertAfterWithManagerInvariantsWithError(cm)
|
||||
self.assertAfterWithGeneratorInvariantsWithError(self.resource)
|
||||
|
||||
@unittest.expectedFailure
|
||||
def testExceptionNormalized(self):
|
||||
cm = mock_contextmanager_generator()
|
||||
def shouldThrow():
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue