當前位置: 首頁>>代碼示例>>Python>>正文


Python inspect.CO_VARKEYWORDS屬性代碼示例

本文整理匯總了Python中inspect.CO_VARKEYWORDS屬性的典型用法代碼示例。如果您正苦於以下問題:Python inspect.CO_VARKEYWORDS屬性的具體用法?Python inspect.CO_VARKEYWORDS怎麽用?Python inspect.CO_VARKEYWORDS使用的例子?那麽, 這裏精選的屬性代碼示例或許可以為您提供幫助。您也可以進一步了解該屬性所在inspect的用法示例。


在下文中一共展示了inspect.CO_VARKEYWORDS屬性的8個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Python代碼示例。

示例1: inspect_func_args

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import CO_VARKEYWORDS [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_kwargs_index

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import CO_VARKEYWORDS [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

示例3: _inspect_func_args

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import CO_VARKEYWORDS [as 別名]
def _inspect_func_args(fn):
    try:
        co_varkeywords = inspect.CO_VARKEYWORDS
    except AttributeError:
        # https://docs.python.org/3/library/inspect.html
        # The flags are specific to CPython, and may not be defined in other
        # Python implementations. Furthermore, the flags are an implementation
        # detail, and can be removed or deprecated in future Python releases.
        spec = compat.inspect_getfullargspec(fn)
        return spec[0], bool(spec[2])
    else:
        # use fn.__code__ plus flags to reduce method call overhead
        co = fn.__code__
        nargs = co.co_argcount
        return (
            list(co.co_varnames[:nargs]),
            bool(co.co_flags & co_varkeywords),
        ) 
開發者ID:sqlalchemy,項目名稱:sqlalchemy,代碼行數:20,代碼來源:langhelpers.py

示例4: CaptureFrameLocals

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import CO_VARKEYWORDS [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_VARKEYWORDS [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_func_args

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import CO_VARKEYWORDS [as 別名]
def inspect_func_args(fn):
        co = fn.__code__
        nargs = co.co_argcount
        names = co.co_varnames
        args = list(names[:nargs])
        has_kw = bool(co.co_flags & CO_VARKEYWORDS)
        return args, has_kw 
開發者ID:jpush,項目名稱:jbox,代碼行數:9,代碼來源:langhelpers.py

示例7: inspect_getfullargspec

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import CO_VARKEYWORDS [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

示例8: get_signature

# 需要導入模塊: import inspect [as 別名]
# 或者: from inspect import CO_VARKEYWORDS [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_VARKEYWORDS屬性示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。