[Python-ideas] documentation for python3 super()
barry at barrys-emacs.org
Sat Jul 2 14:45:12 EDT 2016
> 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?
The one in QObject and the one in Age.
This is the output I get with python 3.5:
$ python3.5 super_example.py
instance of Person.__init__
instance of QObject.__init__
instance of Age.__init__
I see no obvious code that should call Age.__init__, which is why I concluded that there is something about super() that is not documented.
> super() itself is special, it knows the class and instance.
> There are conventions around all of this though. It may be worth documenting those, as long as it is made clear which part of the docs is about conventions (as opposed to how things work).
> There are also opinions about those conventions. Here I am not so sure that they belong in the docs.
> --Guido (mobile)
> On Jul 2, 2016 10:32 AM, "Barry Scott" <barry at barrys-emacs.org <mailto:barry at barrys-emacs.org>> wrote:
> I have read the python3.5 docs for super() and
> https://rhettinger.wordpress.com/2011/05/26/super-considered-super/ <https://rhettinger.wordpress.com/2011/05/26/super-considered-super/>.
> Between the two sources I still have no clear idea of what super() will
> do and why it will doe what it does.
> I hope to get feedback that can be used as the basis to update the python docs.
> For single inheritance the use of super() does not seem to have any surprises.
> But in the case of a class with multiple-inheritance more then 1 function
> may be called by 1 call to super().
> What are the rules for which functions are called by super() in the multiple
> inheritance case?
> Is __init__ special or can other super() calls end up
> calling more then 1 function?
> What is the role of **kwds with super()?
> Here is the code I used to show the __init__ multiple calls.
> The attached example shows that one call to super() causes 2 to
> __init__ of bases of Person. But describe does not follow the pattern
> Age.describe is not called.
> Python-ideas mailing list
> Python-ideas at python.org <mailto:Python-ideas at python.org>
> https://mail.python.org/mailman/listinfo/python-ideas <https://mail.python.org/mailman/listinfo/python-ideas>
> Code of Conduct: http://python.org/psf/codeofconduct/ <http://python.org/psf/codeofconduct/>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Python-ideas