def _get_argspec(func):
"""Returns an inspect.ArgSpec instance given a function object.
We prefer this implementation rather than the inspect module's getargspec
since the latter has a strict check that the passed function is an instance
of FunctionType. Cython functions do not pass this check, but they do implement
the `func_code` and `func_defaults` attributes that we need to produce an Argspec.
This implementation re-uses much of inspect.getargspec but removes the strict
check allowing interface failures to be raised as AttributeError.
See Also:
https://github.com/python/cpython/blob/2.7/Lib/inspect.py
"""
if inspect.ismethod(func):
func = func.im_func
args, varargs, varkw = inspect.getargs(func.func_code)
return inspect.ArgSpec(args, varargs, varkw, func.func_defaults)
评论列表
文章目录