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
评论列表
文章目录