Debian Codegraph @

jupyter_console/utils.py

raw
1 import inspect
2 import typing as t
3 from jupyter_core.utils import run_sync as _run_sync, ensure_async # noqa
4
5
6 T = t.TypeVar("T")
7
8
9 def run_sync(coro: t.Callable[..., t.Union[T, t.Awaitable[T]]]) -> t.Callable[..., T]:
10 """Wraps coroutine in a function that blocks until it has executed.
11
12 Parameters
13 ----------
14 coro : coroutine-function
15 The coroutine-function to be executed.
16
17 Returns
18 -------
19 result :
20 Whatever the coroutine-function returns.
21 """
22 if not inspect.iscoroutinefunction(coro):
23 return t.cast(t.Callable[..., T], coro)
24 return _run_sync(coro)
25