diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2019-09-17 13:20:06 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-09-17 13:20:06 (GMT) |
commit | 3c1786f18b1542e71454f37e3f3ca1ef3eec0e5f (patch) | |
tree | e7ff720f3ea5d59688c1b17350067309fe2121f3 /Lib/test/test_asyncgen.py | |
parent | 5f1590d5e679f4dd0b611ef54ae512f137e78f1b (diff) | |
download | cpython-3c1786f18b1542e71454f37e3f3ca1ef3eec0e5f.zip cpython-3c1786f18b1542e71454f37e3f3ca1ef3eec0e5f.tar.gz cpython-3c1786f18b1542e71454f37e3f3ca1ef3eec0e5f.tar.bz2 |
bpo-38013: make async_generator_athrow object tolerant to throwing exceptions (GH-16070)
Even when the helper is not started yet.
This behavior follows conventional generator one.
There is no reason for `async_generator_athrow` to handle `gen.throw()` differently.
https://bugs.python.org/issue38013
(cherry picked from commit c275312a6284bd319ea33c9abd7e15c230eca43f)
Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
Diffstat (limited to 'Lib/test/test_asyncgen.py')
-rw-r--r-- | Lib/test/test_asyncgen.py | 22 |
1 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/test_asyncgen.py b/Lib/test/test_asyncgen.py index 71b0968..3a8d5fd 100644 --- a/Lib/test/test_asyncgen.py +++ b/Lib/test/test_asyncgen.py @@ -1125,6 +1125,28 @@ class AsyncGenAsyncioTest(unittest.TestCase): res = self.loop.run_until_complete(run()) self.assertEqual(res, [i * 2 for i in range(1, 10)]) + def test_asyncgen_nonstarted_hooks_are_cancellable(self): + # See https://bugs.python.org/issue38013 + messages = [] + + def exception_handler(loop, context): + messages.append(context) + + async def async_iterate(): + yield 1 + yield 2 + + async def main(): + loop = asyncio.get_running_loop() + loop.set_exception_handler(exception_handler) + + async for i in async_iterate(): + break + + asyncio.run(main()) + + self.assertEqual([], messages) + if __name__ == "__main__": unittest.main() |