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

Force base method call

There isn’t and shouldn’t be anything to do that. The closest thing I can think of off hand if something like having this in the base class: public virtual void BeforeFoo(){} public void Foo() { this.BeforeFoo(); //do some stuff this.AfterFoo(); } public virtual void AfterFoo(){} And allow the inheriting class override BeforeFoo and/or AfterFoo

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