mirror of
https://github.com/python/cpython.git
synced 2025-08-02 16:13:13 +00:00
[3.13] gh-128078: Clear exception in anext
before calling _PyGen_SetStopIterationValue
(GH-128780) (#128785)
gh-128078: Clear exception in `anext` before calling `_PyGen_SetStopIterationValue` (GH-128780)
(cherry picked from commit 76ffaef729
)
Co-authored-by: Bénédikt Tran <10796600+picnixz@users.noreply.github.com>
Co-authored-by: Kumar Aditya <kumaraditya@python.org>
This commit is contained in:
parent
632745ade1
commit
66d0636025
4 changed files with 22 additions and 0 deletions
|
@ -1152,6 +1152,23 @@ class AsyncGenAsyncioTest(unittest.TestCase):
|
|||
|
||||
self.loop.run_until_complete(run())
|
||||
|
||||
def test_async_gen_asyncio_anext_tuple_no_exceptions(self):
|
||||
# StopAsyncIteration exceptions should be cleared.
|
||||
# See: https://github.com/python/cpython/issues/128078.
|
||||
|
||||
async def foo():
|
||||
if False:
|
||||
yield (1, 2)
|
||||
|
||||
async def run():
|
||||
it = foo().__aiter__()
|
||||
with self.assertRaises(StopAsyncIteration):
|
||||
await it.__anext__()
|
||||
res = await anext(it, ('a', 'b'))
|
||||
self.assertEqual(res, ('a', 'b'))
|
||||
|
||||
self.loop.run_until_complete(run())
|
||||
|
||||
def test_async_gen_asyncio_anext_stopiteration(self):
|
||||
async def foo():
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue