https://github.com/python/cpython/commit/3a33ccdec821eb5c16aed5fd34cb68e949edbe3a commit: 3a33ccdec821eb5c16aed5fd34cb68e949edbe3a branch: 3.15 author: Miss Islington (bot) <[email protected]> committer: kumaraditya303 <[email protected]> date: 2026-07-26T14:28:51+05:30 summary:
[3.15] gh-154695: fix asyncio.Task eager_start=True with no explicit loop (GH-154697) (#154705) gh-154695: fix asyncio.Task eager_start=True with no explicit loop (GH-154697) (cherry picked from commit f5f50593ad80cab01b942d407f46d216644c5e84) Co-authored-by: Timofei <[email protected]> files: A Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-17-35-14.gh-issue-154695.aQWLLv.rst M Lib/test/test_asyncio/test_tasks.py M Modules/_asynciomodule.c diff --git a/Lib/test/test_asyncio/test_tasks.py b/Lib/test/test_asyncio/test_tasks.py index fa7e21c3536582..5e1cf518f3a38d 100644 --- a/Lib/test/test_asyncio/test_tasks.py +++ b/Lib/test/test_asyncio/test_tasks.py @@ -2752,6 +2752,18 @@ async def main(): self.assertEqual(name, "example") await t + def test_eager_start_true_no_loop(self): + # gh-154695: eager_start must use the resolved loop, not loop=None. + async def asyncfn(): + return 42 + + async def main(): + t = self.__class__.Task(asyncfn(), eager_start=True) + self.assertTrue(t.done()) + self.assertEqual(await t, 42) + + asyncio.run(main(), loop_factory=asyncio.EventLoop) + def test_eager_start_false(self): name = None diff --git a/Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-17-35-14.gh-issue-154695.aQWLLv.rst b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-17-35-14.gh-issue-154695.aQWLLv.rst new file mode 100644 index 00000000000000..6e147cf7f31a88 --- /dev/null +++ b/Misc/NEWS.d/next/Core_and_Builtins/2026-07-25-17-35-14.gh-issue-154695.aQWLLv.rst @@ -0,0 +1,2 @@ +Fix :class:`asyncio.Task` raising :exc:`AttributeError` when created with +``eager_start=True`` and no explicit *loop* argument. diff --git a/Modules/_asynciomodule.c b/Modules/_asynciomodule.c index a314723a46d94e..f9ef789f39dc91 100644 --- a/Modules/_asynciomodule.c +++ b/Modules/_asynciomodule.c @@ -2372,7 +2372,9 @@ _asyncio_Task___init___impl(TaskObj *self, PyObject *coro, PyObject *loop, _PyObject_SetMaybeWeakref((PyObject *)self); #endif if (eager_start) { - PyObject *res = PyObject_CallMethodNoArgs(loop, &_Py_ID(is_running)); + // gh-154695: loop may be None here, future_init() resolved it into task_loop. + PyObject *res = PyObject_CallMethodNoArgs(self->task_loop, + &_Py_ID(is_running)); if (res == NULL) { return -1; } _______________________________________________ Python-checkins mailing list -- [email protected] To unsubscribe send an email to [email protected] https://mail.python.org/mailman3//lists/python-checkins.python.org Member address: [email protected]
