__init__.py 文件源码

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

项目:chaps 作者: ekiro 项目源码 文件源码
def inject_function(f):
    full_arg_spec = inspect.getfullargspec(f)
    args = full_arg_spec.args
    annotations = full_arg_spec.annotations

    def _inner(self):
        container = Container()
        objects = {}
        for arg in args:
            if arg in ('self',):
                continue
            try:
                obj_type = annotations[arg]
            except KeyError:
                obj_type = arg
            obj = container.get_object(obj_type)
            objects[arg] = obj
            setattr(self, arg, obj)
        return f(self, **objects)

    return _inner
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号