Closed MordorianGuy closed 1 year ago
To share a method across classes, the register
decorator can be used. There's no direct equivalent of super
, though it can be simulated by modifying or coercing the arguments.
class Base:
@multimethod
def __init__(self, arg: int):
self.arg = arg
class Subclass(Base):
@Base.__init__.register
def __init__(self, arg: bool):
super().__init__(int(arg))
assert Subclass(True).arg == 1
I would like to dispatch the
__init__
method of a superclass. But it does not work withmultimethod
&multimeta
in the way I expected. Moreover, manual registration is impossible as I cannot access the parent__init__
method inside the class body. I have described more here.