當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。