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: super() is passing wrong parameters while handling diamond inheritance
Type: behavior Stage: resolved
Components: Versions:
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: Nosy List: mark.dickinson, monnerat, steven.daprano
Priority: normal Keywords:

Created on 2019-09-14 13:35 by monnerat, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
super.py monnerat, 2019-09-14 13:35 Python 3 program showing the problem
Messages (2)
msg352429 - (view) Author: Patrick Monnerat (monnerat) Date: 2019-09-14 13:35
Running the attached program outputs:
--------
top.__init__(<__main__.top object at 0x7fc1dea24048>,) called
i1.__init__(<__main__.top object at 0x7fc1dea24048>, 'arg from top') called
i2.__init__(<__main__.top object at 0x7fc1dea24048>, 'arg from i1') called
base.__init__(<__main__.top object at 0x7fc1dea24048>, 'arg from i2') called
base.__init__ returns None
i2.__init__ returns None
i1.__init__ returns None
top.__init__ returns None
--------

i2.__init__() argument is wrong: since it is is not a parent class of i1, it should be "arg from top".

I can understand i2.__init__() is called after i1.__init__() and before base.__init__() but arguments given to super(i1, self).__init__() should not be substituted for calling i2.__init__().
msg352437 - (view) Author: Mark Dickinson (mark.dickinson) * (Python committer) Date: 2019-09-14 15:33
This isn't a bug: super is behaving as designed and as intended here, and indeed with a diamond inheritance structure you'll see super calling "across" from one class to its sibling. That's part of how it works.

There's lots of thoughtful writing out there about super; try the following for starters.

- https://fuhm.net/super-harmful/
- https://rhettinger.wordpress.com/2011/05/26/super-considered-super/
- https://www.artima.com/weblogs/viewpost.jsp?thread=236275
History
Date User Action Args
2022-04-11 14:59:20adminsetgithub: 82352
2019-09-14 15:41:26mark.dickinsonsetstatus: open -> closed
resolution: not a bug
stage: resolved
2019-09-14 15:33:28mark.dickinsonsetnosy: + mark.dickinson
messages: + msg352437
2019-09-14 13:44:48steven.dapranosetnosy: + steven.daprano
2019-09-14 13:35:27monneratcreate