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 == 1Do 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
  
        
    
Uh oh!
There was an error while loading. Please reload this page.
-
I would like to dispatch the
__init__method of a superclass. But it does not work withmultimethod&multimetain 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