0

I'm a beginner and this doubt caught me...

I have the class ProfessorAuxiliar which inherits the attributes of the classes Professor and Aluno. But when using super() it returns TypeError: __init __ () takes 7 positional arguments but 10 were given.

...

class Aluno(Pessoa):

    def __init__(self, nome, sobrenome, cpf, data, sexo, matricula, semestre, curso):
        super().__init__(nome, sobrenome, cpf, data, sexo)
        self.__matricula = matricula
        self.__semestre = semestre
        self.__curso = curso


class Professor(Pessoa):

    __lista_de_indicacoes = []

    def __init__(self, nome, sobrenome, cpf, data, sexo, materia):
        super().__init__(nome, sobrenome, cpf, data, sexo)
        self.__materia = materia

class ProfessorAuxiliar(Professor, Aluno):

    def __init__(self, nome, sobrenome, cpf, data, sexo, materia, matricula, semestre, curso):
        super().__init__(nome, sobrenome, cpf, data, sexo, materia, matricula, semestre, curso)

...

How can I make the ProfessorAuxiliar class inherit all the attributes of the other 2?

martineau
  • 119,623
  • 25
  • 170
  • 301
  • 1
    For further explanation, [this](https://stackoverflow.com/questions/26927571/multiple-inheritance-in-python3-with-different-signatures) thread is very useful. – mustafasencer Aug 14 '20 at 08:54
  • You seem to rely on the constructor for **every** setting. For semester and course this does not appear convincing. As soon as you concentrate person data on a single parent class, you will no longer have collisions (i.e. have to pass the same parameters to different parent classes) and might even no longer need multiple inheritance. – guidot Aug 14 '20 at 11:16

2 Answers2

0

Instead of super, try using parent_classname.__init__() for each of the inherited classes & pass those args accordingly to those parent classes' constructors. EDIT: In the ProfessorAuxiliar class

shreyaskar
  • 375
  • 1
  • 3
  • 14
0

Something like this I think is the correct way.

class ProfessorAuxiliar(Professor, Aluno): 

    def __init__(self, nome, sobrenome, cpf, data, sexo, materia, matricula, semestre, curso):
        Professor.__init__(self,self, nome, sobrenome, cpf, data, sexo, matricula, semestre, curso)
        Aluno.__init__(self,nome, sobrenome, cpf, data, sexo)
Arundeep Chohan
  • 9,779
  • 5
  • 15
  • 32