adt.py 文件源码

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

项目:adt 作者: llllllllll 项目源码 文件源码
def __new__(mcls, name, bases, dict_):
        self = super().__new__(mcls, name, bases, dict_)
        if len(bases) and bases[0] is ADT:
            self._typevars = dict_._typevars
            self._constructors = tuple(dict_._constructors.values())
            constructors = set(self._constructors)
            for constructor in constructors:
                types = concatv(
                    constructor._args,
                    constructor._kwargs.values(),
                )
                for t in types:
                    if isinstance(t, RecursiveType) and t._name != name:
                        raise TypeError(
                            'recursive type name must be the same as the type'
                            ' name, %r != %r' % (
                                t._name,
                                name,
                            ),
                        )
                    if t in constructors:
                        raise TypeError(
                            'constructor %r has arguments that are other'
                            ' constructors' % constructor,
                        )
            if not self._typevars:
                return adt(self, ())
        return self
评论列表
文章目录


问题


面经


文章

微信
公众号

扫码关注公众号