本文整理汇总了Python中inspect.CO_GENERATOR属性的典型用法代码示例。如果您正苦于以下问题:Python inspect.CO_GENERATOR属性的具体用法?Python inspect.CO_GENERATOR怎么用?Python inspect.CO_GENERATOR使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类inspect
的用法示例。
在下文中一共展示了inspect.CO_GENERATOR属性的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __init__
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_GENERATOR [as 别名]
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-')
)
示例2: test_func_1
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_GENERATOR [as 别名]
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))
示例3: dispatch_exception
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_GENERATOR [as 别名]
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.
示例4: dispatch_call
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_GENERATOR [as 别名]
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
示例5: dispatch_return
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_GENERATOR [as 别名]
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
示例6: set_return
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_GENERATOR [as 别名]
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)
示例7: __init__
# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_GENERATOR [as 别名]
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 = ''