from asyncio import Task
from collections.abc import Coroutine
from typing import Any, cast

from gi.repository import Gio


def create(coro: Coroutine[Any, Any, Any]) -> Task[Any]:
    """Create a task with `Gio.Application`."""
    if not (app := Gio.Application.get_default()):
        raise ValueError(app)

    return cast(Task[Any], app.create_asyncio_task(coro))  # type: ignore[attr-defined]
