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
评论列表
文章目录