def get_signature(obj, method_name):
method = getattr(obj, method_name)
# Eat self for unbound methods bc signature doesn't do it
if PY3:
if (inspect.isclass(obj) and
not inspect.ismethod(method) and
not isinstance(
obj.__dict__.get(method_name),
staticmethod)):
method = functools.partial(method, None)
else:
if (isinstance(method, types.UnboundMethodType) and
method.__self__ is None):
method = functools.partial(method, None)
try:
return signature(method)
except:
return None
评论列表
文章目录