[Python] Should super always be at the top of an __init__ method, or can it be at the bottom?

Discussão em 'Python' iniciado por Stack, Junho 26, 2025.

  1. Stack

    Stack Membro Participativo

    In most Python examples, when super is used to call a parent class's constructors, it appears at the top.

    Is it bad form to have it at the bottom of an init method?

    In the examples below, super is at the bottom of A's constructor, but at the top of B's constructor.

    class A:
    def __init__(self):
    # Do some stuff
    b = result_of_complex_operation()
    super(A, self).__init__(b)

    class B:
    def __init__(self):
    super(A, self).__init__(b)
    # Do some stuff

    Continue reading...

Compartilhe esta Página