returns a proxy object that delegates method calls to parents or a class of a sibling type.
This proxy is an object that acts as part of a call to the method of the parent class. This is not the class itself; rather, there is enough information so that you can use it to call the methods of the parent class.
If you call __init__() , you get your own, local, subclass function __init__ . When you call super() , you get this proxy object that redirects you to the methods of the parent class. Thus, when you call super().__init__() , this proxy redirects the call to the parent method __init__ .
Similarly, if you were to call super().foo , you would get the foo method from the parent class - again, redirected by this proxy.
Is that clear to you?
ANSWERS TO COMMENTS
But this should mean that this proxy object is passed to init () when super () is run. init () right?
Wrong. The proxy object is similar to the package name, for example, calling math.sqrt (). You do not pass the math to sqrt, you use it to indicate which sqrt you are using. If you want to pass init to the proxy, the call will be init (super ()). Of course, this challenge would be semantically ridiculous.
When we have to actually pass ourselves in, which is the sc object in my example.
No, you do not pass by sc ; this is the result of an object creation call (internal __new__ method), which includes an init call. For __init__ the self object is a new element created for you by the Python runtime system. For most class methods, this first argument (called self convention, this in other languages) is the object that calls the method.
Prune
source share