當前位置: 首頁>>代碼示例>>Python>>正文


Python inspect.isasyncgenfunction方法代碼示例

本文整理匯總了Python中inspect.isasyncgenfunction方法的典型用法代碼示例。如果您正苦於以下問題:Python inspect.isasyncgenfunction方法的具體用法?Python inspect.isasyncgenfunction怎麽用?Python inspect.isasyncgenfunction使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在inspect的用法示例。


在下文中一共展示了inspect.isasyncgenfunction方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: solve_generator

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def solve_generator(
    *, call: Callable, stack: AsyncExitStack, sub_values: Dict[str, Any]
) -> Any:
    if is_gen_callable(call):
        cm = contextmanager_in_threadpool(contextmanager(call)(**sub_values))
    elif is_async_gen_callable(call):
        if not inspect.isasyncgenfunction(call):
            # asynccontextmanager from the async_generator backfill pre python3.7
            # does not support callables that are not functions or methods.
            # See https://github.com/python-trio/async_generator/issues/32
            #
            # Expand the callable class into its __call__ method before decorating it.
            # This approach will work on newer python versions as well.
            call = getattr(call, "__call__", None)
        cm = asynccontextmanager(call)(**sub_values)
    return await stack.enter_async_context(cm) 
開發者ID:tiangolo,項目名稱:fastapi,代碼行數:18,代碼來源:utils.py

示例2: _imp

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def _imp(cls, loaded):
        """
        Returns the operation implemention from a loaded entrypoint object, or
        None if its not an operation implemention or doesn't have the imp
        parameter which is an operation implemention.
        """
        for obj in [getattr(loaded, "imp", None), loaded]:
            if inspect.isclass(obj) and issubclass(obj, cls):
                return obj
        if (
            inspect.isfunction(loaded)
            or inspect.isgeneratorfunction(loaded)
            or inspect.iscoroutinefunction(loaded)
            or inspect.isasyncgenfunction(loaded)
        ):
            return op(loaded).imp
        return None 
開發者ID:intel,項目名稱:dffml,代碼行數:19,代碼來源:base.py

示例3: protect_with_lock

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def protect_with_lock(fn):
    """Use as a decorator to protect an async method with `self._lock`.

    Also works with async gen method so it can be used for `open_cursor`.
    """

    if inspect.isasyncgenfunction(fn):

        @functools.wraps(fn)
        async def wrapper(self, *args, **kwargs):
            async with self._lock:
                async for item in fn.__get__(self)(*args, **kwargs):
                    yield item

    else:
        assert inspect.iscoroutinefunction(fn)

        @functools.wraps(fn)
        async def wrapper(self, *args, **kwargs):
            async with self._lock:
                return await fn.__get__(self)(*args, **kwargs)

    return wrapper 
開發者ID:Scille,項目名稱:parsec-cloud,代碼行數:25,代碼來源:local_database.py

示例4: pytest_collection_modifyitems

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def pytest_collection_modifyitems(items):
    """add asyncio marker to all async tests"""
    for item in items:
        if inspect.iscoroutinefunction(item.obj):
            item.add_marker("asyncio")
        if hasattr(inspect, "isasyncgenfunction"):
            # double-check that we aren't mixing yield and async def
            assert not inspect.isasyncgenfunction(item.obj) 
開發者ID:jupyterhub,項目名稱:ldapauthenticator,代碼行數:10,代碼來源:conftest.py

示例5: is_async_gen_callable

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def is_async_gen_callable(call: Callable) -> bool:
    if inspect.isasyncgenfunction(call):
        return True
    call = getattr(call, "__call__", None)
    return inspect.isasyncgenfunction(call) 
開發者ID:tiangolo,項目名稱:fastapi,代碼行數:7,代碼來源:utils.py

示例6: add

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def add(self, updater):
        assert isinstance(updater, Updater)
        fn = updater.updater
        if six.PY3 and inspect.isasyncgenfunction(fn):
            self.async_loop.call_soon_threadsafe(self._add_async_generator_updater, updater)
        elif six.PY3 and inspect.iscoroutinefunction(fn):
            self.async_loop.call_soon_threadsafe(self._add_async_updater, updater)
        elif inspect.isgeneratorfunction(fn):
            self._add_generator_updater(updater)
        elif callable(fn):
            self._add_callable_updater(updater)
        else:
            raise ValueError('Invalid updater: {}'.format(fn)) 
開發者ID:dankilman,項目名稱:awe,代碼行數:15,代碼來源:element_updater.py

示例7: is_async_function

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def is_async_function(func: object) -> bool:
    """Return True if the given function seems to be an async function or async generator"""
    return iscoroutinefunction(func) or (
        sys.version_info >= (3, 6) and inspect.isasyncgenfunction(func)
    ) 
開發者ID:pytest-dev,項目名稱:pytest,代碼行數:7,代碼來源:compat.py

示例8: do_run

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def do_run(self):
        async with self:
            if inspect.isasyncgenfunction(self.run):
                return [res async for res in self.run()]
            else:
                return await self.run() 
開發者ID:intel,項目名稱:dffml,代碼行數:8,代碼來源:cmd.py

示例9: decorate_advising_asyncgenerator_py35

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def decorate_advising_asyncgenerator_py35(advising_function, cutpoint_function, bind):
    assert isasyncgenfunction(cutpoint_function) or iscoroutinefunction(cutpoint_function)

    async def advising_asyncgenerator_wrapper_py35(*args, **kwargs):
        if bind:
            advisor = advising_function(cutpoint_function, *args, **kwargs)
        else:
            advisor = advising_function(*args, **kwargs)
        if not isgenerator(advisor):
            raise ExpectedGenerator("advising_function %s did not return a generator." % advising_function)
        try:
            advice = next(advisor)
            while True:
                logdebug('Got advice %r from %s', advice, advising_function)
                if advice is Proceed or advice is None or isinstance(advice, Proceed):
                    if isinstance(advice, Proceed):
                        args = advice.args
                        kwargs = advice.kwargs
                    gen = cutpoint_function(*args, **kwargs)
                    try:
                        result = await gen
                    except BaseException:
                        advice = advisor.throw(*sys.exc_info())
                    else:
                        try:
                            advice = advisor.send(result)
                        except StopIteration:
                            return result
                    finally:
                        gen.close()
                elif advice is Return:
                    return
                elif isinstance(advice, Return):
                    return advice.value
                else:
                    raise UnacceptableAdvice("Unknown advice %s" % advice)
        finally:
            advisor.close()
    return mimic(advising_asyncgenerator_wrapper_py35, cutpoint_function) 
開發者ID:ionelmc,項目名稱:python-aspectlib,代碼行數:41,代碼來源:py35support.py

示例10: isasyncfunction

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def isasyncfunction(obj):
        if isasyncgenfunction is None:
            return iscoroutinefunction(obj)
        else:
            return isasyncgenfunction(obj) or iscoroutinefunction(obj) 
開發者ID:ionelmc,項目名稱:python-aspectlib,代碼行數:7,代碼來源:__init__.py

示例11: __init__

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def __init__(self, func: Callable[..., Any], args, kwargs):
        if not inspect.isasyncgenfunction(func):
            raise RuntimeError('Context manager function must be '
                               'an async-generator')
        self._agen = func(*args, **kwargs)
        self.func = func
        self.args = args
        self.kwargs = kwargs
        self.yield_return = None 
開發者ID:achimnol,項目名稱:aiotools,代碼行數:11,代碼來源:server.py

示例12: __init__

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def __init__(self, func: Callable[..., Any], args, kwargs):
            if not inspect.isasyncgenfunction(func):
                raise RuntimeError('Context manager function must be '
                                   'an async-generator')
            self._agen = func(*args, **kwargs)
            self.func = func
            self.args = args
            self.kwargs = kwargs 
開發者ID:achimnol,項目名稱:aiotools,代碼行數:10,代碼來源:context.py

示例13: traverse

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def traverse(self, func):
        """
        Traverses an async function or generator, yielding each result.

        This function is private. The class should be used as an iterator instead of using this method.
        """

        if inspect.isasyncgenfunction(func):
            async for send, result in AsyncSender(func(*self.args)):
                send((yield result))
        else:
            yield await func(*self.args) 
開發者ID:Gorialis,項目名稱:jishaku,代碼行數:14,代碼來源:compilation.py

示例14: is_async_generator_fixture

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def is_async_generator_fixture(self):
        return inspect.isasyncgenfunction(inspect.unwrap(self.fn)) 
開發者ID:darrenburns,項目名稱:ward,代碼行數:4,代碼來源:fixtures.py

示例15: typed

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import isasyncgenfunction [as 別名]
def typed(obj):
    """Compiles a function or class with cython.

    Use annotations for static type declarations. Example:

        import statically

        @statically.typed
        def add_two(x: int) -> int:
            two: int = 2
            return x + two
    """
    if not _can_cython_inline():
        return obj
    elif has_async_gen_fun and inspect.isasyncgenfunction(obj):
        raise TypeError("Async generator funcions are not supported.")

    source = _get_source_code(obj)
    frame = inspect.currentframe().f_back
    if inspect.isclass(obj):
        locals_ = frame.f_locals
    else:
        locals_ = _get_outer_variables(obj)
    with warnings.catch_warnings():
        warnings.simplefilter("ignore")
        compiled = cython.inline(source, locals=locals_,
                                 globals=frame.f_globals, quiet=True)
        return compiled[obj.__name__] 
開發者ID:AlanCristhian,項目名稱:statically,代碼行數:30,代碼來源:statically.py


注:本文中的inspect.isasyncgenfunction方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。