Beispiel #1
0
def new_ensure_async(  # type: ignore
    self, func: Callable[..., Any]
) -> Callable[..., Awaitable[Any]]:
    if is_coroutine_function(func):
        return func
    else:
        return asyncio.coroutine(func)
Beispiel #2
0
def ensure_sync(self, func: Callable) -> Callable:  # type: ignore
    if is_coroutine_function(func):

        @wraps(func)
        def _wrapper(*args: Any, **kwargs: Any) -> Any:
            return sync_with_context(func(*args, **kwargs))

        return _wrapper
    else:
        return func
Beispiel #3
0
def new_ensure_async(  # type: ignore
        self, func: Callable[..., Any]) -> Callable[..., Awaitable[Any]]:

    if is_coroutine_function(func):
        return func
    else:

        @wraps(func)
        async def _wrapper(*args: Any, **kwargs: Any) -> Any:
            result = func(*args, **kwargs)
            if iscoroutine(result):
                return await result
            else:
                return result

        return _wrapper
Beispiel #4
0
def test_is_coroutine_function() -> None:
    async def async_func() -> None:
        pass

    assert is_coroutine_function(async_func)
    assert is_coroutine_function(partial(async_func))