Martijn Pieters Sep 30 '16 at 16:25.
Why cant the super constructor be invoked from an enum constructor?
Use Case 2: Super can be called upon in a dynamic execution environment for multiple or collaborative inheritance.
B this way you dont have to repeat the name of the class in the call to super.Either way, now youll understand that super isnt as bad as other devs purport it.Kdbanman Jun 2 '15 at 19:45 4 @kdbanman: This will work with new-style classes, but one of the reasons to use new-style classes is to not have to do it this way.First, well take a regular class definition and modify it by adding the super function.The super function is extremely useful when youre concerned about forward compatibility.Ultimately, it eliminates the need to declare certain characteristics of a class, provided you use it correctly.In the constructor it has super but the class implements interface which of course doesnt have a constructor.Mcve: class A(object def _init self super(self._class self)._init class B(A pass, b).You can use super and not have to directly name the class you're inheriting from.
Dont you agree this is much easier?
Learn More About the Super Function We know a lot about the super function and the Python language in general, but we dont know everything!
Many developers found the documentation unclear, and the function itself to be tricky to implement.
You only need to make a few changes as opposed to a lot.On the plus side, super can be used to handle diamond-shaped inheritance.Implicit super constructor Employee is undefined.Alpha Romeo May 10 at 13:41 add a comment up vote 3 down vote I use the following formula that extends previous answers: class A(object def _init self print "world" class B(A def _init self print "hello" super(self._class self)._init B This way you don't have.Dened Jun 1 '16 at 8:11 7 This will lead to infinite recursion errors when you subclass.
In Python 3 and above, the syntax for super is: super.methoName(args whereas the normal way to call super (in older builds of Python) is: super(subClass, instance).method(args as you can see, the newer version of Python makes the syntax a little simpler.
What Is the Super Function for Again?