super().__init__() refuses to take arguments despite parent init requiring an argument

Viewed 38

My code attempts to pass through arguments for parent initialisation through the child like so:

class Mother:
    def __init__(self, hobbies):
        self.hobbies = hobbies

class Father:
    def __init__(self, job):
        self.job = job

class Son(Father, Mother):
    def __init__(self, job, hobbies, name):
        self.job = job
        self.hobbies = hobbies
        self.name = name
        super(Father, self).__init__(job)
        super(Mother, self).__init__(hobbies)

son = Son("programmer", "cooking", "Will")

This throws the following error:

Traceback (most recent call last):
  File "e:\Code\Python Code\OOP\polymorphism.py", line 27, in <module>
    son = Son("programmer", "cooking", "Will")
  File "e:\Code\Python Code\OOP\polymorphism.py", line 25, in __init__
    super(Mother, self).__init__(hobbies)
TypeError: object.__init__() takes exactly one argument (the instance to initialize)

When I tried removing the argument, and passed through: super(Mother, self).__init__() I received no error. But, upon printing son.hobbies, the program outputs "programmer", which is supposed to be son.job. I have no idea why this happens. Could someone explain this quirk?

0 Answers
Related