Previously, calling inspect.signature on a Haiku class would result in an
inferred signature to be equivalent to def f(*args, **kwargs). This is
suboptimal because (1) interactive systems like Colab can't provide useful
help with the signature, and (2) systems like
Fiddle can't eagerly enforce parameter
names.
Although there are a few other ways to implement this functionality (such as
by computing the signature and assigning it during __call__ or __new__),
these are incompatible with @dataclasses.dataclass decorators, which
compute a new __init__ function + signature after the class is defined. As
a result, the @property approach works best. If this becomes a performance
problem, it can be memoized, although systems arguably should be doing their
own memoizing (e.g. Fiddle already does this).
Add
__signature__
tohk.ModuleMetaclass
.Previously, calling
inspect.signature
on a Haiku class would result in an inferred signature to be equivalent todef f(*args, **kwargs)
. This is suboptimal because (1) interactive systems like Colab can't provide useful help with the signature, and (2) systems like Fiddle can't eagerly enforce parameter names.Although there are a few other ways to implement this functionality (such as by computing the signature and assigning it during
__call__
or__new__
), these are incompatible with@dataclasses.dataclass
decorators, which compute a new__init__
function + signature after the class is defined. As a result, the@property
approach works best. If this becomes a performance problem, it can be memoized, although systems arguably should be doing their own memoizing (e.g. Fiddle already does this).