metaestimators.py 文件源码

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

项目:skutil 作者: tgsmith61591 项目源码 文件源码
def __get__(self, obj, type=None):
        # raise an AttributeError if the attribute is not present on the object
        if obj is not None:
            # delegate only on instances, not the classes.
            # this is to allow access to the docstrings.
            for delegate_name in self.delegate_names:
                try:
                    delegate = getattr(obj, delegate_name)
                except AttributeError:
                    continue
                else:
                    if not isinstance(delegate, self.instance_type):
                        raise TypeError('delegate (%s) is not an instance of %s' 
                                        % (delegate, self.instance_type))
                    break
            else:
                attrgetter(self.delegate_names[-1])(obj)

        # lambda, but not partial, allows help() to work with update_wrapper
        out = lambda *args, **kwargs: self.fn(obj, *args, **kwargs)
        # update the docstring of the returned function
        update_wrapper(out, self.fn)
        return out
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号