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


Python inspect.CO_VARARGS属性代码示例

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


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

示例1: inspect_func_args

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_VARARGS [as 别名]
def inspect_func_args(fn):
        if py3k:
            co = fn.__code__
        else:
            co = fn.func_code

        nargs = co.co_argcount
        names = co.co_varnames
        args = list(names[:nargs])

        varargs = None
        if co.co_flags & CO_VARARGS:
            varargs = co.co_varnames[nargs]
            nargs = nargs + 1
        varkw = None
        if co.co_flags & CO_VARKEYWORDS:
            varkw = co.co_varnames[nargs]

        if py3k:
            return args, varargs, varkw, fn.__defaults__
        else:
            return args, varargs, varkw, fn.func_defaults 
开发者ID:jpush,项目名称:jbox,代码行数:24,代码来源:compat.py

示例2: get_args_index

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_VARARGS [as 别名]
def get_args_index(target) -> int:
    """
    Returns the index of the "*args" parameter if such a parameter exists in
    the function arguments or -1 otherwise.

    :param target:
        The target function for which the args index should be determined
    :return:
        The arguments index if it exists or -1 if not
    """

    code = target.__code__

    if not bool(code.co_flags & inspect.CO_VARARGS):
        return -1

    return code.co_argcount + code.co_kwonlyargcount 
开发者ID:sernst,项目名称:cauldron,代码行数:19,代码来源:params.py

示例3: get_kwargs_index

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_VARARGS [as 别名]
def get_kwargs_index(target) -> int:
    """
    Returns the index of the "**kwargs" parameter if such a parameter exists in
    the function arguments or -1 otherwise.

    :param target:
        The target function for which the kwargs index should be determined
    :return:
        The keyword arguments index if it exists or -1 if not
    """

    code = target.__code__

    if not bool(code.co_flags & inspect.CO_VARKEYWORDS):
        return -1

    return (
        code.co_argcount +
        code.co_kwonlyargcount +
        (1 if code.co_flags & inspect.CO_VARARGS else 0)
    ) 
开发者ID:sernst,项目名称:cauldron,代码行数:23,代码来源:params.py

示例4: CaptureFrameLocals

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_VARARGS [as 别名]
def CaptureFrameLocals(self, frame):
    """Captures local variables and arguments of the specified frame.

    Args:
      frame: frame to capture locals and arguments.

    Returns:
      (arguments, locals) tuple.
    """
    # Capture all local variables (including method arguments).
    variables = {n: self.CaptureNamedVariable(n, v, 1,
                                              self.default_capture_limits)
                 for n, v in six.viewitems(frame.f_locals)}

    # Split between locals and arguments (keeping arguments in the right order).
    nargs = frame.f_code.co_argcount
    if frame.f_code.co_flags & inspect.CO_VARARGS: nargs += 1
    if frame.f_code.co_flags & inspect.CO_VARKEYWORDS: nargs += 1

    frame_arguments = []
    for argname in frame.f_code.co_varnames[:nargs]:
      if argname in variables: frame_arguments.append(variables.pop(argname))

    return (frame_arguments, list(six.viewvalues(variables))) 
开发者ID:GoogleCloudPlatform,项目名称:cloud-debug-python,代码行数:26,代码来源:capture_collector.py

示例5: inspect_getargspec

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_VARARGS [as 别名]
def inspect_getargspec(func):
    """getargspec based on fully vendored getfullargspec from Python 3.3."""

    if inspect.ismethod(func):
        func = func.__func__
    if not inspect.isfunction(func):
        raise TypeError("{!r} is not a Python function".format(func))

    co = func.__code__
    if not inspect.iscode(co):
        raise TypeError("{!r} is not a code object".format(co))

    nargs = co.co_argcount
    names = co.co_varnames
    nkwargs = co.co_kwonlyargcount if py3k else 0
    args = list(names[:nargs])

    nargs += nkwargs
    varargs = None
    if co.co_flags & inspect.CO_VARARGS:
        varargs = co.co_varnames[nargs]
        nargs = nargs + 1
    varkw = None
    if co.co_flags & inspect.CO_VARKEYWORDS:
        varkw = co.co_varnames[nargs]

    return ArgSpec(args, varargs, varkw, func.__defaults__) 
开发者ID:remg427,项目名称:misp42splunk,代码行数:29,代码来源:compat.py

示例6: inspect_getfullargspec

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_VARARGS [as 别名]
def inspect_getfullargspec(func):
    """Fully vendored version of getfullargspec from Python 3.3."""

    if inspect.ismethod(func):
        func = func.__func__
    if not inspect.isfunction(func):
        raise TypeError("{!r} is not a Python function".format(func))

    co = func.__code__
    if not inspect.iscode(co):
        raise TypeError("{!r} is not a code object".format(co))

    nargs = co.co_argcount
    names = co.co_varnames
    nkwargs = co.co_kwonlyargcount if py3k else 0
    args = list(names[:nargs])
    kwonlyargs = list(names[nargs : nargs + nkwargs])

    nargs += nkwargs
    varargs = None
    if co.co_flags & inspect.CO_VARARGS:
        varargs = co.co_varnames[nargs]
        nargs = nargs + 1
    varkw = None
    if co.co_flags & inspect.CO_VARKEYWORDS:
        varkw = co.co_varnames[nargs]

    return FullArgSpec(
        args,
        varargs,
        varkw,
        func.__defaults__,
        kwonlyargs,
        func.__kwdefaults__ if py3k else None,
        func.__annotations__ if py3k else {},
    ) 
开发者ID:sqlalchemy,项目名称:dogpile.cache,代码行数:38,代码来源:compat.py

示例7: get_signature

# 需要导入模块: import inspect [as 别名]
# 或者: from inspect import CO_VARARGS [as 别名]
def get_signature(func):
    """
    Gathers information about the call signature of `func`.
    """
    code = func.__code__

    # Names of regular parameters
    parameters = tuple(code.co_varnames[:code.co_argcount])

    # Flags
    has_varargs = bool(code.co_flags & inspect.CO_VARARGS)
    has_varkw = bool(code.co_flags & inspect.CO_VARKEYWORDS)
    has_kwonly = bool(code.co_kwonlyargcount)

    # A mapping of parameter names to default values
    default_values = func.__defaults__ or ()
    defaults = dict(zip(parameters[-len(default_values):], default_values))

    # Type annotations for all parameters
    type_hints = typing.get_type_hints(func) if typing else func.__annotations__
    types = tuple(normalize_type(type_hints.get(param, AnyType)) for param in parameters)

    # Type annotations for required parameters
    required = types[:-len(defaults)] if defaults else types

    # Complexity
    complexity = tuple(map(type_complexity, types)) if typing else None

    return Signature(parameters, types, complexity, defaults, required,
                     has_varargs, has_varkw, has_kwonly) 
开发者ID:bintoro,项目名称:overloading.py,代码行数:32,代码来源:overloading.py


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