Rietveld Code Review Tool
Help | Bug tracker | Discussion group | Source code | Sign in
(34369)

Unified Diff: Lib/test/test_generators.py

Issue 25612: nested try..excepts don't work correctly for generators
Patch Set: Created 3 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Please Sign in to add in-line comments.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | Python/ceval.c » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
--- a/Lib/test/test_generators.py Sun Nov 08 11:09:13 2015 +0000
+++ b/Lib/test/test_generators.py Thu Nov 12 19:15:12 2015 -0500
@@ -260,6 +260,89 @@
# hence no warning.
next(g)
+ def test_nested_try_1(self):
+ 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)
+ try:
+ coro.throw(SubError())
+ except MainError as ex:
+ self.assertIsNone(ex.__cause__)
+ self.assertIsNone(ex.__context__)
+ except Exception as ex:
+ self.fail('MainError expected; got {!r}'.format(ex))
+ else:
+ self.fail('MainError expected; got no exception')
+
+ def test_nested_try_2(self):
+ class MainError(Exception):
+ pass
+
+ class SubError(Exception):
+ pass
+
+ def main():
+ try:
+ raise MainError()
+ except MainError:
+ yield
+
+ coro = main()
+ coro.send(None)
+ try:
+ coro.throw(SubError())
+ except SubError as ex:
+ self.assertIsNone(ex.__cause__)
+ self.assertIs(type(ex.__context__), MainError)
+ except Exception as ex:
+ self.fail('SubError expected; got {!r}'.format(ex))
+ else:
+ self.fail('SubError expected; got no exception')
+
+ def test_nested_try_3(self):
+ class MainError(Exception):
+ pass
+
+ class SubError(Exception):
+ pass
+
+ def main():
+ try:
+ raise MainError()
+ except MainError as ex:
+ try:
+ yield
+ except SubError:
+ pass
+ raise ex
+
+ coro = main()
+ coro.send(None)
+ try:
+ coro.throw(SubError())
+ except MainError as ex:
+ self.assertIsNone(ex.__cause__)
+ self.assertIsNone(ex.__context__)
+ except Exception as ex:
+ self.fail('MainError expected; got {!r}'.format(ex))
+ else:
+ self.fail('MainError expected; got no exception')
+
class YieldFromTests(unittest.TestCase):
def test_generator_gi_yieldfrom(self):
« no previous file with comments | « no previous file | Python/ceval.c » ('j') | no next file with comments »

RSS Feeds Recent Issues | This issue
This is Rietveld 894c83f36cb7+