params.py 文件源码

python
阅读 31 收藏 0 点赞 0 评论 0

项目:cauldron 作者: sernst 项目源码 文件源码
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)
    )
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号