This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Misleading descriptions about built-in `super.`
Type: Stage:
Components: Documentation Versions: Python 2.7
process
Status: closed Resolution: duplicate
Dependencies: Superseder: super() documentation isn't very clear
View: 23674
Assigned To: docs@python Nosy List: Juchen Zeng, docs@python, eric.araujo, eryksun, ezio.melotti, georg.brandl, martin.panter, r.david.murray
Priority: normal Keywords:

Created on 2015-12-01 08:02 by Juchen Zeng, last changed 2022-04-11 14:58 by admin. This issue is now closed.

Messages (5)
msg255643 - (view) Author: Juchen Zeng (Juchen Zeng) Date: 2015-12-01 08:02
A few days ago, I was learning built-in type `super` through [python official doc](https://docs.python.org/2/library/functions.html#super).  
And I was mislead by its documentation, in the part of how `__mro__` resolution works. Below is the part which confuse me:

"""
super(type[, object-or-type])

# ISSUE IRRELEVANT DOC OMITTED

The __mro__ attribute of the type lists the method resolution search order used by both getattr() and super(). The attribute is dynamic and can change whenever the inheritance hierarchy is updated.
"""

From the description of the doc we can see that `super()` takes two arguments, the first is `type` and the second is an optional `object-or-type`. So, when I saw the doc statement: `The __mro__ attribute of the type lists the method resolution search order used by both getattr() and super(). `, I naturally thought here the `type` refers to the compulsory first `type` argument. But after doing a series of [experiments][EXP_REF]. It turns out in `super()` was using the second `type`'s `__mro__` attribute! And if the second argument is an object, it will use `object.__class__.__mro__` as its resolution order. Unless a learner experimented it throughly like me, he will have lots of difficulty to figured out that `type` mentioned in the doc refers to the second optional argument. I think here the doc should be clearly specified that the second argument's `__mro__` is what super relies on. I suggest to add distinctions on arguments name or add more clarification informations in the doc here.

By the way, the python3 document has the same issue.  
If you decided to fix this, maybe you want to fix its python3 version, too.

 

[EXP_REF]: http://stackoverflow.com/questions/33890918/how-does-super-interacts-with-a-classs-mro-attribute-in-multiple-inheri/33891281#33891281
msg255645 - (view) Author: Martin Panter (martin.panter) * (Python committer) Date: 2015-12-01 09:54
I agree. I think Issue 23674 already covers this. I will try to propose some changes there.
msg255656 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-12-01 16:07
Just FYI, 'super' is not a type, it is a function that returns a proxy.  (In python3 there is also compiler magic involved in the no-argument form, but it is still a function :)
msg255663 - (view) Author: Eryk Sun (eryksun) * (Python triager) Date: 2015-12-01 16:59
> Just FYI, 'super' is not a type

No, super is a type:

    >>> super
    <type 'super'>

It's one of 3 types defined in Objects/typeobject.c: 

    PyBaseObject_Type : "object"
    PyType_Type       : "type"
    PySuper_Type      : "super"

A super instance (CPython superobject) has the following members: 

     __thisclass__  : the class invoking super()
     __self__       : the instance invoking super()
     __self_class__ : the type of the instance invoking super()

super has a cutsom __getattribute__ (tp_getattro) slot, super_getattro, which proxies attribute access starting at the parent/sibling of __thisclass__ in the __mro__ of __self_class__. 

super even defines a __get__ descriptor (tp_descr_get) method, super_descr_get, though I've never used it as such.
msg255664 - (view) Author: R. David Murray (r.david.murray) * (Python committer) Date: 2015-12-01 17:05
Heh.  OK, learn something new every day.
History
Date User Action Args
2022-04-11 14:58:24adminsetgithub: 69958
2015-12-01 17:05:51r.david.murraysetmessages: + msg255664
2015-12-01 16:59:08eryksunsetnosy: + eryksun
messages: + msg255663
2015-12-01 16:07:36r.david.murraysetnosy: + r.david.murray

messages: + msg255656
title: Misleading descriptions about built-in type `super.` -> Misleading descriptions about built-in `super.`
2015-12-01 09:54:47martin.pantersetstatus: open -> closed

nosy: + martin.panter
messages: + msg255645

superseder: super() documentation isn't very clear
resolution: duplicate
2015-12-01 08:02:50Juchen Zengcreate