[Python-ideas] documentation for python3 super()

Random832 random832 at fastmail.com
Sat Jul 2 16:18:55 EDT 2016


On Sat, Jul 2, 2016, at 14:45, Barry Scott wrote:
>
> > On 2 Jul 2016, at 18:58, Guido van Rossum <gvanrossum at gmail.com>
> > wrote:
> >
> > No, super() does not (directly) call multiple functions. The
> > function it calls has to call the next with another super() call.
> > Also, __init__() is not special, nor is **kwds
> >
>
> The thing I do not understand is why did super() call 2 __init__
> functions given the code I attached?

Because you called it twice. Well, actually three times:

1. Person calls super().__init__ which calls QObject.__init__.
2. QObject calls it *again*, which calls Age.__init__.
3. Age calls it again, which calls object.__init__, which does nothing
and prints nothing.

With each method you call, the named keywords are stripped off of
**kwds; none of them are left by the time it gets to Age, so none are
passed to object - otherwise you would get an error:

TypeError: object.__init__() takes no parameters.


More information about the Python-ideas mailing list