当前位置: 首页>>代码示例>>Python>>正文


Python inspect.CO_ITERABLE_COROUTINE属性代码示例

本文整理汇总了Python中inspect.CO_ITERABLE_COROUTINE属性的典型用法代码示例。如果您正苦于以下问题:Python inspect.CO_ITERABLE_COROUTINE属性的具体用法?Python inspect.CO_ITERABLE_COROUTINE怎么用?Python inspect.CO_ITERABLE_COROUTINE使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在inspect的用法示例。


在下文中一共展示了inspect.CO_ITERABLE_COROUTINE属性的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _from_coroutine

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_ITERABLE_COROUTINE [as 别名]
def _from_coroutine() -> bool:
        """Check if called from the coroutine function.

        Determine whether the current function is called from a
        coroutine function (native coroutine, generator-based coroutine,
        or asynchronous generator function).

        NOTE: That it's only recommended to use for debugging, not as
        part of your production code's functionality.
        """
        try:
            frame = inspect.currentframe()
            if frame is None:
                return False
            coroutine_function_flags = (
                inspect.CO_COROUTINE  # pylint: disable=no-member
                | inspect.CO_ASYNC_GENERATOR  # pylint: disable=no-member
                | inspect.CO_ITERABLE_COROUTINE  # pylint: disable=no-member
            )
            if (
                frame is not None
                and frame.f_back is not None
                and frame.f_back.f_back is not None
            ):
                return bool(
                    frame.f_back.f_back.f_code.co_flags & coroutine_function_flags
                )
            return False
        finally:
            del frame 
开发者ID:datadvance,项目名称:DjangoChannelsGraphqlWs,代码行数:32,代码来源:subscription.py

示例2: test_genfunc

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_ITERABLE_COROUTINE [as 别名]
def test_genfunc(self):
        def gen(): yield
        self.assertIs(types.coroutine(gen), gen)
        self.assertIs(types.coroutine(types.coroutine(gen)), gen)

        self.assertTrue(gen.__code__.co_flags & inspect.CO_ITERABLE_COROUTINE)
        self.assertFalse(gen.__code__.co_flags & inspect.CO_COROUTINE)

        g = gen()
        self.assertTrue(g.gi_code.co_flags & inspect.CO_ITERABLE_COROUTINE)
        self.assertFalse(g.gi_code.co_flags & inspect.CO_COROUTINE)

        self.assertIs(types.coroutine(gen), gen) 
开发者ID:Microvellum,项目名称:Fluid-Designer,代码行数:15,代码来源:test_types.py

示例3: __init__

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_ITERABLE_COROUTINE [as 别名]
def __init__(self, iterator):
        self.iterator = iterator
        code_mock = NonCallableMock(spec_set=CodeType)
        code_mock.co_flags = inspect.CO_ITERABLE_COROUTINE
        self.__dict__['__code__'] = code_mock 
开发者ID:testing-cabal,项目名称:mock,代码行数:7,代码来源:mock.py

示例4: is_awaitable

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_ITERABLE_COROUTINE [as 别名]
def is_awaitable(value: Any) -> bool:
    """Return true if object can be passed to an ``await`` expression.

    Instead of testing if the object is an instance of abc.Awaitable, it checks
    the existence of an `__await__` attribute. This is much faster.
    """
    return (
        # check for coroutine objects
        isinstance(value, CoroutineType)
        # check for old-style generator based coroutine objects
        or isinstance(value, GeneratorType)
        and bool(value.gi_code.co_flags & CO_ITERABLE_COROUTINE)
        # check for other awaitables (e.g. futures)
        or hasattr(value, "__await__")
    ) 
开发者ID:graphql-python,项目名称:graphql-core,代码行数:17,代码来源:is_awaitable.py


注:本文中的inspect.CO_ITERABLE_COROUTINE属性示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。