继承

class B:
    def gg(self):
        print(__class__)


class A(B):
    def gg(self):
        print(__class__)


class C(A):
    def d(self):
        print(__class__)


class D:
    def gg(self):
        print(__class__)


class F(B):
    def gg(self):
        print(__class__)


class E(C, D, F):
    def e(self):
        print(__class__)

    def me(self):
        super().gg()


print([x.__name__ for x in E.__mro__])

           B
          /  \
        /      \
       A        |
       |        |
       C    D   F    
        \   |  /
            E

>>> ['E', 'C', 'A', 'D', 'F', 'B', 'object']

C3 Linearization Algorithm : C3 Linearization algorithm is an algorithm that uses new-style classes. It is used to remove an inconsistency created by DLR Algorithm. It has certain limitation they are:

  • Children precede their parents

  • If a class inherits from multiple classes, they are kept in the order specified in the tuple of the base class.

C3 Linearization Algorithm works on three rules:

  • Inheritance graph determines the structure of method resolution order.

  • User have to visit the super class only after the method of the local classes are visited.

  • Monotonicity

Last updated

Was this helpful?