r58901 - in python/branches/release25-maint: Lib/contextlib.py Lib/test/test_with.py Misc/NEWS
![](https://secure.gravatar.com/avatar/8ac615df352a970211b0e3d94a307c6d.jpg?s=120&d=mm&r=g)
Author: nick.coghlan Date: Wed Nov 7 13:26:40 2007 New Revision: 58901 Modified: python/branches/release25-maint/Lib/contextlib.py python/branches/release25-maint/Lib/test/test_with.py python/branches/release25-maint/Misc/NEWS Log: Fix issue #1705170 (backport from trunk) Modified: python/branches/release25-maint/Lib/contextlib.py ============================================================================== --- python/branches/release25-maint/Lib/contextlib.py (original) +++ python/branches/release25-maint/Lib/contextlib.py Wed Nov 7 13:26:40 2007 @@ -25,6 +25,10 @@ else: raise RuntimeError("generator didn't stop") else: + if value is None: + # Need to force instantiation so we can reliably + # tell if we get the same exception back + value = type() try: self.gen.throw(type, value, traceback) raise RuntimeError("generator didn't stop after throw()") Modified: python/branches/release25-maint/Lib/test/test_with.py ============================================================================== --- python/branches/release25-maint/Lib/test/test_with.py (original) +++ python/branches/release25-maint/Lib/test/test_with.py Wed Nov 7 13:26:40 2007 @@ -440,6 +440,7 @@ self.assertAfterWithGeneratorInvariantsNoError(self.bar) def testRaisedStopIteration1(self): + # From bug 1462485 @contextmanager def cm(): yield @@ -451,6 +452,7 @@ self.assertRaises(StopIteration, shouldThrow) def testRaisedStopIteration2(self): + # From bug 1462485 class cm(object): def __enter__(self): pass @@ -463,7 +465,21 @@ self.assertRaises(StopIteration, shouldThrow) + def testRaisedStopIteration3(self): + # Another variant where the exception hasn't been instantiated + # From bug 1705170 + @contextmanager + def cm(): + yield + + def shouldThrow(): + with cm(): + raise iter([]).next() + + self.assertRaises(StopIteration, shouldThrow) + def testRaisedGeneratorExit1(self): + # From bug 1462485 @contextmanager def cm(): yield @@ -475,6 +491,7 @@ self.assertRaises(GeneratorExit, shouldThrow) def testRaisedGeneratorExit2(self): + # From bug 1462485 class cm (object): def __enter__(self): pass Modified: python/branches/release25-maint/Misc/NEWS ============================================================================== --- python/branches/release25-maint/Misc/NEWS (original) +++ python/branches/release25-maint/Misc/NEWS Wed Nov 7 13:26:40 2007 @@ -32,6 +32,9 @@ Library ------- +- Issue #1705170: contextlib.contextmanager was still swallowing + StopIteration in some cases. This should no longer happen. + - Bug #1307: Fix smtpd so it doesn't raise an exception when there is no arg. - ctypes will now work correctly on 32-bit systems when Python is
participants (1)
-
nick.coghlan