File tree Expand file tree Collapse file tree 1 file changed +27
-4
lines changed
Expand file tree Collapse file tree 1 file changed +27
-4
lines changed Original file line number Diff line number Diff line change 1010from gettext import gettext as _
1111from inspect import iscoroutine
1212
13- import anyio
14-
1513from ._compat import isatty
1614from ._compat import strip_ansi
1715from .exceptions import Abort
@@ -171,9 +169,34 @@ def prompt_func(text: str) -> str:
171169 async def run_prompt_func (text : str ) -> str :
172170 return prompt_func (text )
173171 else :
172+ # Not having a hard dependency on any async runtime is harder than it looks.
173+ try :
174+ import anyio
175+
176+ except ImportError :
177+ try :
178+ import sniffio # type: ignore
179+ except ImportError :
180+ backend = "asyncio"
181+ else :
182+ backend = sniffio .current_async_library ()
183+
184+ if backend == "trio" :
185+ import trio
186+
187+ def run_prompt_func (text : str ) -> t .Awaitable [str ]:
188+ return trio .to_thread .run_sync (prompt_func , text )
189+
190+ else :
191+ import asyncio
192+
193+ def run_prompt_func (text : str ) -> t .Awaitable [str ]:
194+ return asyncio .to_thread (prompt_func , text )
195+
196+ else :
174197
175- def run_prompt_func (text : str ) -> t .Awaitable [str ]:
176- return anyio .to_thread .run_sync (prompt_func , text )
198+ def run_prompt_func (text : str ) -> t .Awaitable [str ]:
199+ return anyio .to_thread .run_sync (prompt_func , text )
177200
178201 if value_proc is None :
179202 value_proc = convert_type (type , default )
You can’t perform that action at this time.
0 commit comments