From 8727e37e0dd342c55a74ae9c3ef517e42ae44650 Mon Sep 17 00:00:00 2001 From: Ash <73482956+ascopes@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:50:43 +0100 Subject: [PATCH 1/2] Fix issue where no anyio backend is produced FIxes an issue where running the outer group produces an exception "RuntimeError: Backend None Unknown". If no anyio backend is specified, then asyncio is used as the default. --- src/asyncclick/core.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/asyncclick/core.py b/src/asyncclick/core.py index 7688904a1..15a3c73be 100644 --- a/src/asyncclick/core.py +++ b/src/asyncclick/core.py @@ -1520,7 +1520,7 @@ async def _main_shell_completion( def __call__( self, *args: t.Any, - _anyio_backend: str | None = None, + _anyio_backend: str = "asyncio", _anyio_backend_options: dict[str, t.Any] | None = None, **kwargs: t.Any, ) -> t.Any: From 8e870cd5dd3f50c8e8a0763dd591db2c84e97242 Mon Sep 17 00:00:00 2001 From: Ash <73482956+ascopes@users.noreply.github.com> Date: Fri, 10 Oct 2025 15:54:05 +0100 Subject: [PATCH 2/2] Update core.py to move asyncio fallback logic to preseve existing behaviour --- src/asyncclick/core.py | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/src/asyncclick/core.py b/src/asyncclick/core.py index 15a3c73be..621617835 100644 --- a/src/asyncclick/core.py +++ b/src/asyncclick/core.py @@ -1520,7 +1520,7 @@ async def _main_shell_completion( def __call__( self, *args: t.Any, - _anyio_backend: str = "asyncio", + _anyio_backend: str | None, _anyio_backend_options: dict[str, t.Any] | None = None, **kwargs: t.Any, ) -> t.Any: @@ -1529,6 +1529,9 @@ def __call__( If you are already inside an async event loop, call ``await`` :meth:`main` instead. + If no backend is found and anyio is not installed, then ``asyncio`` is + used for the backend. + :param _anyio_backend: The backend to use for the event loop. :param _anyio_backend_options: Any options to pass to the backend. @@ -1553,7 +1556,7 @@ def __call__( import trio return trio.run(self._main, main, args, kwargs) - if _anyio_backend == "asyncio": + if _anyio_backend == "asyncio" or _anyio_backend is None: import asyncio return asyncio.run(self._main(main, args, kwargs))