#๐Ÿ”’ Strange execution order

4 messages ยท Page 1 of 1 (latest)

empty grove
#
class Level1():
    def __init__(self):
        print("INIT of First...!!!")
class Level2_1(Level1):
    def __init__(self):
        super().__init__()
        print("INIT of Second - First...!!!")
class Level2_2(Level1):
    def __init__(self):
        super().__init__()
        print("INIT of Second - Second...!!!")
class Level2_3(Level1):
    def __init__(self):
        super().__init__()
        print("INIT of Second - Third...!!!")
class Level3(Level2_1, Level2_2, Level2_3):
    def __init__(self):
        super().__init__()
        print("INIT of Third...!!!")
class Combined(Level3):
    def __init__(self):
        super().__init__()
c = Combined()
print(Combined.__mro__)
# Real Execution Order: 1,2,4,5,8,9,12,13,16,17,20,21,23,22,18,6,10,14,3,15,11,7,19,24,25
# My guess:             1,2,4,5,8,9,12,13,16,17,20,21,23,22,18,6,3,7,10,11,14,15,19,24,25
'''Output:
INIT of First...!!!
INIT of Second - Third...!!!
INIT of Second - Second...!!!
INIT of Second - First...!!!
INIT of Third...!!!
(<class '__main__.Combined'>, <class '__main__.Level3'>, <class '__main__.Level2_1'>, <class '__main__.Level2_2'>, <class '__main__.Level2_3'>, <class '__main__.Level1'>, <class 'object'>)
'''

I must have not understood how super works. I thought it executes any class passed in the argument.

rotund thicketBOT
#

@empty grove

Python help channel opened

Remember to:

  • Ask your Python question, not if you can ask or if there's an expert who can help.
  • Show a code sample as text (rather than a screenshot) and the error message, if you've got one.
  • Explain what you expect to happen and what actually happens.

:warning: Do not pip install anything that isn't related to your question, especially if asked to over DMs.

rotund thicketBOT
#

@empty grove

Python help channel closed

This help channel has been closed and it's no longer possible to send messages here. If your question wasn't answered, feel free to create a new post in #1035199133436354600. To maximize your chances of getting a response, check out this guide on asking good questions.