noninstantiable.py 文件源码

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

项目:apification 作者: Quantify-world 项目源码 文件源码
def __new__(cls, cls_name, cls_parents, cls_dict):
        ret = super(NoninstantiableMeta,cls).__new__(cls, cls_name, cls_parents, cls_dict)
        for name in dir(ret):
            value = getattr(ret, name)
            if isinstance(value, MethodType):  
                if not getattr(ret, '_allow_self_as_first_arg', False) and 'self' in inspect.getargs(value.func_code).args[:1]:
                    warn_message = SELF_WARN_MESSAGE % {'cls': cls_name, 'method': name}
                    warnings.warn(warn_message, SyntaxWarning)
                new_method = classmethod(value.im_func)
                setattr(ret, name, new_method) # turn all methods to classmethods
        ret.__init__ = classmethod(cls._prevent_instantiating)  # You shall not pass!
        return ret
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号