diff options
| author | Nick Coghlan <ncoghlan@gmail.com> | 2007-11-07 12:26:40 +0000 |
|---|---|---|
| committer | Nick Coghlan <ncoghlan@gmail.com> | 2007-11-07 12:26:40 +0000 |
| commit | e53fcfd7d32343bd1a5780a85ed9bfde0c8f79b6 (patch) | |
| tree | 7c2f3fc31aad51e8a1450d79774229853bd5bdba | |
| parent | 2e49f781cb299bb1c832b663dc50d7d4fad67321 (diff) | |
| download | cpython-git-e53fcfd7d32343bd1a5780a85ed9bfde0c8f79b6.tar.gz | |
Fix issue #1705170 (backport from trunk)
| -rw-r--r-- | Lib/contextlib.py | 4 | ||||
| -rw-r--r-- | Lib/test/test_with.py | 17 | ||||
| -rw-r--r-- | Misc/NEWS | 3 |
3 files changed, 24 insertions, 0 deletions
diff --git a/Lib/contextlib.py b/Lib/contextlib.py index a807c42ce4..c4fab1bbfa 100644 --- a/Lib/contextlib.py +++ b/Lib/contextlib.py @@ -25,6 +25,10 @@ class GeneratorContextManager(object): 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()") diff --git a/Lib/test/test_with.py b/Lib/test/test_with.py index 57505085dd..8242c912c5 100644 --- a/Lib/test/test_with.py +++ b/Lib/test/test_with.py @@ -440,6 +440,7 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin): self.assertAfterWithGeneratorInvariantsNoError(self.bar) def testRaisedStopIteration1(self): + # From bug 1462485 @contextmanager def cm(): yield @@ -451,6 +452,7 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin): self.assertRaises(StopIteration, shouldThrow) def testRaisedStopIteration2(self): + # From bug 1462485 class cm(object): def __enter__(self): pass @@ -463,7 +465,21 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin): 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 @@ class ExceptionalTestCase(unittest.TestCase, ContextmanagerAssertionMixin): self.assertRaises(GeneratorExit, shouldThrow) def testRaisedGeneratorExit2(self): + # From bug 1462485 class cm (object): def __enter__(self): pass @@ -32,6 +32,9 @@ Core and builtins 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 |
