Skip to content

asyncio.Task raises AttributeError when no loop is passed #154695

Closed

Description

@deadlovelll

Bug report

Bug description:

asyncio.Task(coro, eager_start=True) raises AttributeError when the loop is not passed

Reproducer:

import asyncio

async def coro():
    return 42

async def main():
    t = asyncio.Task(coro(), eager_start=True)
    print(t.done(), await t)

asyncio.run(main())

Expected:

True 42

But actually:

AttributeError: 'NoneType' object has no attribute 'is_running'

For example python implementation of the Task works correctly:

import asyncio
import asyncio.tasks


async def coro():
    return 42


async def main():
    task = asyncio.tasks._PyTask(coro(), eager_start=True)
    print(task.done(), await task)


asyncio.run(main())

Output:

True 42

Proposed fix:

From:

PyObject *res = PyObject_CallMethodNoArgs(loop, &_Py_ID(is_running));

To:

PyObject *res = PyObject_CallMethodNoArgs(self->task_loop,
                                          &_Py_ID(is_running));

I have a fix ready

CPython versions tested on:

CPython main branch

Operating systems tested on:

macOS

Linked PRs

Activity

  1. added a commit that references this issue on Jul 25, 2026
  2. added a commit that references this issue on Jul 26, 2026
  3. added 2 commits that reference this issue on Jul 26, 2026
  4. added a commit that references this issue on Aug 14, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    type-bugAn unexpected behavior, bug, or error

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions