mirror of
https://github.com/python/cpython.git
synced 2025-08-29 05:05:03 +00:00
Move exc state to generator. Fixes bpo-25612 (#1773)
Move exception state information from frame objects to coroutine (generator/thread) object where it belongs.
This commit is contained in:
parent
91dc64ba3f
commit
ae3087c638
13 changed files with 188 additions and 164 deletions
|
@ -1097,6 +1097,62 @@ class ExceptionTests(unittest.TestCase):
|
|||
self.assertIn("test message", report)
|
||||
self.assertTrue(report.endswith("\n"))
|
||||
|
||||
def test_yield_in_nested_try_excepts(self):
|
||||
#Issue #25612
|
||||
class MainError(Exception):
|
||||
pass
|
||||
|
||||
class SubError(Exception):
|
||||
pass
|
||||
|
||||
def main():
|
||||
try:
|
||||
raise MainError()
|
||||
except MainError:
|
||||
try:
|
||||
yield
|
||||
except SubError:
|
||||
pass
|
||||
raise
|
||||
|
||||
coro = main()
|
||||
coro.send(None)
|
||||
with self.assertRaises(MainError):
|
||||
coro.throw(SubError())
|
||||
|
||||
def test_generator_doesnt_retain_old_exc2(self):
|
||||
#Issue 28884#msg282532
|
||||
def g():
|
||||
try:
|
||||
raise ValueError
|
||||
except ValueError:
|
||||
yield 1
|
||||
self.assertEqual(sys.exc_info(), (None, None, None))
|
||||
yield 2
|
||||
|
||||
gen = g()
|
||||
|
||||
try:
|
||||
raise IndexError
|
||||
except IndexError:
|
||||
self.assertEqual(next(gen), 1)
|
||||
self.assertEqual(next(gen), 2)
|
||||
|
||||
def test_raise_in_generator(self):
|
||||
#Issue 25612#msg304117
|
||||
def g():
|
||||
yield 1
|
||||
raise
|
||||
yield 2
|
||||
|
||||
with self.assertRaises(ZeroDivisionError):
|
||||
i = g()
|
||||
try:
|
||||
1/0
|
||||
except:
|
||||
next(i)
|
||||
next(i)
|
||||
|
||||
|
||||
class ImportErrorTests(unittest.TestCase):
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue