callable.py 文件源码

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

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


问题


面经


文章

微信
公众号

扫码关注公众号