Python inspect.CO_GENERATOR Examples
The following are 17
code examples of inspect.CO_GENERATOR().
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: bdb.py From ironpython3 with Apache License 2.0 | 6 votes |
def dispatch_exception(self, frame, arg): if self.stop_here(frame): # When stepping with next/until/return in a generator frame, skip # the internal StopIteration exception (with no traceback) # triggered by a subiterator run with the 'yield from' statement. if not (frame.f_code.co_flags & CO_GENERATOR and arg[0] is StopIteration and arg[2] is None): self.user_exception(frame, arg) if self.quitting: raise BdbQuit # Stop at the StopIteration or GeneratorExit exception when the user # has set stopframe in a generator by issuing a return command, or a # next/until command at the last statement in the generator before the # exception. elif (self.stopframe and frame is not self.stopframe and self.stopframe.f_code.co_flags & CO_GENERATOR and arg[0] in (StopIteration, GeneratorExit)): self.user_exception(frame, arg) if self.quitting: raise BdbQuit return self.trace_dispatch # Normally derived classes don't override the following # methods, but they may if they want to redefine the # definition of stopping and breakpoints.
Example #2
Source File: test_coroutines.py From android_universal with MIT License | 6 votes |
def test_func_1(self): async def foo(): return 10 f = foo() self.assertIsInstance(f, types.CoroutineType) self.assertTrue(bool(foo.__code__.co_flags & inspect.CO_COROUTINE)) self.assertFalse(bool(foo.__code__.co_flags & inspect.CO_GENERATOR)) self.assertTrue(bool(f.cr_code.co_flags & inspect.CO_COROUTINE)) self.assertFalse(bool(f.cr_code.co_flags & inspect.CO_GENERATOR)) self.assertEqual(run_async(f), ([], 10)) self.assertEqual(run_async__await__(foo()), ([], 10)) def bar(): pass self.assertFalse(bool(bar.__code__.co_flags & inspect.CO_COROUTINE))
Example #3
Source File: bdb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def dispatch_exception(self, frame, arg): if self.stop_here(frame): # When stepping with next/until/return in a generator frame, skip # the internal StopIteration exception (with no traceback) # triggered by a subiterator run with the 'yield from' statement. if not (frame.f_code.co_flags & CO_GENERATOR and arg[0] is StopIteration and arg[2] is None): self.user_exception(frame, arg) if self.quitting: raise BdbQuit # Stop at the StopIteration or GeneratorExit exception when the user # has set stopframe in a generator by issuing a return command, or a # next/until command at the last statement in the generator before the # exception. elif (self.stopframe and frame is not self.stopframe and self.stopframe.f_code.co_flags & CO_GENERATOR and arg[0] in (StopIteration, GeneratorExit)): self.user_exception(frame, arg) if self.quitting: raise BdbQuit return self.trace_dispatch # Normally derived classes don't override the following # methods, but they may if they want to redefine the # definition of stopping and breakpoints.
Example #4
Source File: test_coroutines.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 6 votes |
def test_func_1(self): async def foo(): return 10 f = foo() self.assertIsInstance(f, types.CoroutineType) self.assertTrue(bool(foo.__code__.co_flags & inspect.CO_COROUTINE)) self.assertFalse(bool(foo.__code__.co_flags & inspect.CO_GENERATOR)) self.assertTrue(bool(f.cr_code.co_flags & inspect.CO_COROUTINE)) self.assertFalse(bool(f.cr_code.co_flags & inspect.CO_GENERATOR)) self.assertEqual(run_async(f), ([], 10)) self.assertEqual(run_async__await__(foo()), ([], 10)) def bar(): pass self.assertFalse(bool(bar.__code__.co_flags & inspect.CO_COROUTINE))
Example #5
Source File: tracer.py From snoop with MIT License | 6 votes |
def __init__(self, frame): self.frame = frame self.local_reprs = {} self.last_line_no = frame.f_lineno self.comprehension_variables = OrderedDict() self.source = Source.for_frame(frame) code = frame.f_code self.is_generator = code.co_flags & inspect.CO_GENERATOR self.had_exception = False if is_comprehension_frame(frame): self.comprehension_type = ( re.match(r'<(\w+)comp>', code.co_name).group(1).title() + u' comprehension' ) else: self.comprehension_type = '' self.is_ipython_cell = ( code.co_name == '<module>' and code.co_filename.startswith('<ipython-input-') )
Example #6
Source File: bdb.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def dispatch_exception(self, frame, arg): if self.stop_here(frame): # When stepping with next/until/return in a generator frame, skip # the internal StopIteration exception (with no traceback) # triggered by a subiterator run with the 'yield from' statement. if not (frame.f_code.co_flags & CO_GENERATOR and arg[0] is StopIteration and arg[2] is None): self.user_exception(frame, arg) if self.quitting: raise BdbQuit # Stop at the StopIteration or GeneratorExit exception when the user # has set stopframe in a generator by issuing a return command, or a # next/until command at the last statement in the generator before the # exception. elif (self.stopframe and frame is not self.stopframe and self.stopframe.f_code.co_flags & CO_GENERATOR and arg[0] in (StopIteration, GeneratorExit)): self.user_exception(frame, arg) if self.quitting: raise BdbQuit return self.trace_dispatch # Normally derived classes don't override the following # methods, but they may if they want to redefine the # definition of stopping and breakpoints.
Example #7
Source File: test_coroutines.py From Fluid-Designer with GNU General Public License v3.0 | 6 votes |
def test_func_1(self): async def foo(): return 10 f = foo() self.assertIsInstance(f, types.CoroutineType) self.assertTrue(bool(foo.__code__.co_flags & inspect.CO_COROUTINE)) self.assertFalse(bool(foo.__code__.co_flags & inspect.CO_GENERATOR)) self.assertTrue(bool(f.cr_code.co_flags & inspect.CO_COROUTINE)) self.assertFalse(bool(f.cr_code.co_flags & inspect.CO_GENERATOR)) self.assertEqual(run_async(f), ([], 10)) self.assertEqual(run_async__await__(foo()), ([], 10)) def bar(): pass self.assertFalse(bool(bar.__code__.co_flags & inspect.CO_COROUTINE))
Example #8
Source File: bdb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def set_return(self, frame): """Stop when returning from the given frame.""" if frame.f_code.co_flags & CO_GENERATOR: self._set_stopinfo(frame, None, -1) else: self._set_stopinfo(frame.f_back, frame)
Example #9
Source File: bdb.py From ironpython3 with Apache License 2.0 | 5 votes |
def dispatch_call(self, frame, arg): # XXX 'arg' is no longer used if self.botframe is None: # First call of dispatch since reset() self.botframe = frame.f_back # (CT) Note that this may also be None! return self.trace_dispatch if not (self.stop_here(frame) or self.break_anywhere(frame)): # No need to trace this function return # None # Ignore call events in generator except when stepping. if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: return self.trace_dispatch self.user_call(frame, arg) if self.quitting: raise BdbQuit return self.trace_dispatch
Example #10
Source File: bdb.py From ironpython3 with Apache License 2.0 | 5 votes |
def dispatch_return(self, frame, arg): if self.stop_here(frame) or frame == self.returnframe: # Ignore return events in generator except when stepping. if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: return self.trace_dispatch try: self.frame_returning = frame self.user_return(frame, arg) finally: self.frame_returning = None if self.quitting: raise BdbQuit # The user issued a 'next' or 'until' command. if self.stopframe is frame and self.stoplineno != -1: self._set_stopinfo(None, None) return self.trace_dispatch
Example #11
Source File: bdb.py From ironpython3 with Apache License 2.0 | 5 votes |
def set_return(self, frame): """Stop when returning from the given frame.""" if frame.f_code.co_flags & CO_GENERATOR: self._set_stopinfo(frame, None, -1) else: self._set_stopinfo(frame.f_back, frame)
Example #12
Source File: tracer2.py From executing with MIT License | 5 votes |
def __init__(self, frame): self.frame = frame self.local_reprs = {} self.last_line_no = frame.f_lineno self.comprehension_variables = OrderedDict() self.source = Source.for_frame(frame) self.is_generator = frame.f_code.co_flags & inspect.CO_GENERATOR self.had_exception = False if is_comprehension_frame(frame): self.comprehension_type = ( re.match(r'<(\w+)comp>', frame.f_code.co_name).group(1).title() + u' comprehension' ) else: self.comprehension_type = ''
Example #13
Source File: bdb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def dispatch_return(self, frame, arg): if self.stop_here(frame) or frame == self.returnframe: # Ignore return events in generator except when stepping. if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: return self.trace_dispatch try: self.frame_returning = frame self.user_return(frame, arg) finally: self.frame_returning = None if self.quitting: raise BdbQuit # The user issued a 'next' or 'until' command. if self.stopframe is frame and self.stoplineno != -1: self._set_stopinfo(None, None) return self.trace_dispatch
Example #14
Source File: bdb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def dispatch_call(self, frame, arg): # XXX 'arg' is no longer used if self.botframe is None: # First call of dispatch since reset() self.botframe = frame.f_back # (CT) Note that this may also be None! return self.trace_dispatch if not (self.stop_here(frame) or self.break_anywhere(frame)): # No need to trace this function return # None # Ignore call events in generator except when stepping. if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: return self.trace_dispatch self.user_call(frame, arg) if self.quitting: raise BdbQuit return self.trace_dispatch
Example #15
Source File: bdb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def dispatch_return(self, frame, arg): if self.stop_here(frame) or frame == self.returnframe: # Ignore return events in generator except when stepping. if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: return self.trace_dispatch try: self.frame_returning = frame self.user_return(frame, arg) finally: self.frame_returning = None if self.quitting: raise BdbQuit # The user issued a 'next' or 'until' command. if self.stopframe is frame and self.stoplineno != -1: self._set_stopinfo(None, None) return self.trace_dispatch
Example #16
Source File: bdb.py From Fluid-Designer with GNU General Public License v3.0 | 5 votes |
def dispatch_call(self, frame, arg): # XXX 'arg' is no longer used if self.botframe is None: # First call of dispatch since reset() self.botframe = frame.f_back # (CT) Note that this may also be None! return self.trace_dispatch if not (self.stop_here(frame) or self.break_anywhere(frame)): # No need to trace this function return # None # Ignore call events in generator except when stepping. if self.stopframe and frame.f_code.co_flags & CO_GENERATOR: return self.trace_dispatch self.user_call(frame, arg) if self.quitting: raise BdbQuit return self.trace_dispatch
Example #17
Source File: bdb.py From Project-New-Reign---Nemesis-Main with GNU General Public License v3.0 | 5 votes |
def set_return(self, frame): """Stop when returning from the given frame.""" if frame.f_code.co_flags & CO_GENERATOR: self._set_stopinfo(frame, None, -1) else: self._set_stopinfo(frame.f_back, frame)