Is there a way to dispatch superclass methods? #75
MordorianGuy
started this conversation in
General
Replies: 2 comments 1 reply
-
To share a method across classes, the 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 |
Beta Was this translation helpful? Give feedback.
0 replies
-
Thank you very much for your answer! It has helped. Although taking into account that a superclass is likely third-party and its methods are not multimethod objects, the resulting construction looks like this in my case. class Base:
def __init__(self, arg: int):
self.arg = arg
class Subclass(Base):
@multimethod(Base.__init__).register
def __init__(self, arg: bool):
super().__init__(int(arg))
assert Subclass(True).arg == 1 Do you mind if I retell this in the initial StackOverflow question with the citation? |
Beta Was this translation helpful? Give feedback.
1 reply
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
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.Beta Was this translation helpful? Give feedback.
All reactions