def inspect_callable(obj):
if type(obj) in (types.FunctionType, types.BuiltinFunctionType):
return Callable(obj)
if type(obj) == type:
return Callable(obj, init=True)
if type(obj) == types.MethodType:
return Callable(obj.__func__, self_obj=obj.__self__)
if type(obj) == MethodWrapperType:
return Callable(
getattr(obj.__objclass__, obj.__name__),
self_obj=obj.__self__)
if type(obj) == WrapperDescriptorType:
return Callable(obj)
if hasattr(obj, '__call__'):
return inspect_callable(obj.__call__)
raise AttributeError
评论列表
文章目录