Which of the 4 ways to call super() in Python 3 to use?

Let’s use the following classes for demonstration: class A(object): def m(self): print(‘m’) class B(A): pass Unbound super object doesn’t dispatch attribute access to class, you have to use descriptor protocol: >>> super(B).m Traceback (most recent call last): File “<stdin>”, line 1, in <module> AttributeError: ‘super’ object has no attribute ‘m’ >>> super(B).__get__(B(), B) <super: <class … Read more

Python super method and calling alternatives

Consider the following situation: class A(object): def __init__(self): print(‘Running A.__init__’) super(A,self).__init__() class B(A): def __init__(self): print(‘Running B.__init__’) # super(B,self).__init__() A.__init__(self) class C(A): def __init__(self): print(‘Running C.__init__’) super(C,self).__init__() class D(B,C): def __init__(self): print(‘Running D.__init__’) super(D,self).__init__() foo=D() So the classes form a so-called inheritance diamond: A / \ B C \ / D Running the code yields … Read more

Java: Calling a super method which calls an overridden method

The keyword super doesn’t “stick”. Every method call is handled individually, so even if you got to SuperClass.method1() by calling super, that doesn’t influence any other method call that you might make in the future. That means there is no direct way to call SuperClass.method2() from SuperClass.method1() without going though SubClass.method2() unless you’re working with … Read more