Python inspect.CO_ITERABLE_COROUTINE Examples
The following are 6
code examples of inspect.CO_ITERABLE_COROUTINE().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
inspect
, or try the search function
.
Example #1
Source File: subscription.py From DjangoChannelsGraphqlWs with MIT License | 5 votes |
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
Example #2
Source File: test_types.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
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)
Example #3
Source File: mock.py From mock with BSD 2-Clause "Simplified" License | 5 votes |
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
Example #4
Source File: is_awaitable.py From graphql-core with MIT License | 5 votes |
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__") )
Example #5
Source File: test_types.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
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)
Example #6
Source File: test_types.py From android_universal with MIT License | 5 votes |
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)