From 17cddcb8ac2fb5de27843ef4c42077d1c82db098 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 8 Dec 2022 18:20:15 +0530 Subject: [PATCH 1/3] add support for generators --- Doc/library/asyncio-task.rst | 4 ++++ Doc/whatsnew/3.12.rst | 3 +++ Lib/test/test_asyncio/test_tasks.py | 16 ++++++++++++++++ 3 files changed, 23 insertions(+) diff --git a/Doc/library/asyncio-task.rst b/Doc/library/asyncio-task.rst index 5f1449e1b599ef..a0900cd25a7731 100644 --- a/Doc/library/asyncio-task.rst +++ b/Doc/library/asyncio-task.rst @@ -804,6 +804,10 @@ Waiting Primitives .. versionchanged:: 3.11 Passing coroutine objects to ``wait()`` directly is forbidden. + .. versionchanged:: 3.12 + Added support for generators yielding tasks. + + .. function:: as_completed(aws, *, timeout=None) Run :ref:`awaitable objects ` in the *aws* diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index b9c668543e1b73..f69229e5320045 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -241,6 +241,9 @@ asyncio :mod:`asyncio` does not support legacy generator-based coroutines. (Contributed by Kumar Aditya in :gh:`102748`.) +* :func:`asyncio.wait` now accepts generators yielding tasks. + (Contributed by Kumar Aditya in :gh:`78530`) + inspect ------- diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index 5b935b526541a1..731fa0c5a60b9b 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -1373,6 +1373,22 @@ async def foo(): self.assertEqual(res, 42) self.assertAlmostEqual(0.15, loop.time()) + + def test_wait_generator(self): + async def func(a): + return a + + loop = self.new_test_loop() + + async def main(): + tasks = (self.new_task(loop, func(i)) for i in range(10)) + done, pending = await asyncio.wait(tasks, return_when=asyncio.ALL_COMPLETED) + self.assertEqual(len(done), 10) + self.assertEqual(len(pending), 0) + + loop.run_until_complete(main()) + + def test_as_completed(self): def gen(): From 1369707311b07eef6483cc2cadb14201717bb870 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 16 Mar 2023 16:43:06 +0000 Subject: [PATCH 2/3] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Library/2023-03-16-16-43-04.gh-issue-78530.Lr8eq_.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Library/2023-03-16-16-43-04.gh-issue-78530.Lr8eq_.rst diff --git a/Misc/NEWS.d/next/Library/2023-03-16-16-43-04.gh-issue-78530.Lr8eq_.rst b/Misc/NEWS.d/next/Library/2023-03-16-16-43-04.gh-issue-78530.Lr8eq_.rst new file mode 100644 index 00000000000000..bdb46d08c5c4af --- /dev/null +++ b/Misc/NEWS.d/next/Library/2023-03-16-16-43-04.gh-issue-78530.Lr8eq_.rst @@ -0,0 +1 @@ +:func:`asyncio.wait` now accepts generators yielding tasks. Patch by Kumar Aditya. From 635267da98c52687c2bee57f66c51c5956f13a88 Mon Sep 17 00:00:00 2001 From: Kumar Aditya <59607654+kumaraditya303@users.noreply.github.com> Date: Thu, 16 Mar 2023 22:15:09 +0530 Subject: [PATCH 3/3] Update Doc/whatsnew/3.12.rst --- Doc/whatsnew/3.12.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/whatsnew/3.12.rst b/Doc/whatsnew/3.12.rst index f69229e5320045..686d968f5180ac 100644 --- a/Doc/whatsnew/3.12.rst +++ b/Doc/whatsnew/3.12.rst @@ -242,7 +242,7 @@ asyncio (Contributed by Kumar Aditya in :gh:`102748`.) * :func:`asyncio.wait` now accepts generators yielding tasks. - (Contributed by Kumar Aditya in :gh:`78530`) + (Contributed by Kumar Aditya in :gh:`78530`.) inspect -------