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: Incomplete Comparison to C++ Methods
Type: enhancement Stage: resolved
Components: Documentation Versions: Python 3.11
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: docs@python Nosy List: docs@python, eric.araujo, gvanrossum, jharmse
Priority: normal Keywords:

Created on 2022-01-17 21:03 by jharmse, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (6)
msg410823 - (view) Author: Jorgen Harmse (jharmse) Date: 2022-01-17 21:03
The description of classes mentions twice that methods are like C++ virtual member functions, but the truth is a bit stranger.

Even __init__ seems to act like a virtual function, so there is no guarantee that the base-class part of a derived-class instance is properly constructed.

Even if the base class __init__ is called, it may behave erratically. The object is already considered to belong to the derived class, so any method calls will resolve to the derived class. In C++, the run-time type inside any constructor or destructor always matches the compile-time type. Derived-class members are not called because those methods would attempt to use parts of the object that haven't been constructed yet or have already been destructed. Python takes no such precautions, and programmers should be warned accordingly. (I think the solution is to be very careful of calling any other method from __init__.)
msg411172 - (view) Author: Éric Araujo (eric.araujo) * (Python committer) Date: 2022-01-21 19:18
Maybe the reference should be removed entirely!  Nowadays there may be more people knowing Python and how its methods work than C++.
msg411186 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-01-21 21:19
Just because __init__ is extra weird doesn't mean that other methods aren't roughly like C++.

But I can't find the text the OP refers to. Without a specific pointer (at least a URL and quoted text) this issue is non-actionable and should probably be closed.
msg411205 - (view) Author: Jorgen Harmse (jharmse) Date: 2022-01-21 22:52
There may be more people who use Python, but there are strange semantics that cause problems even for experienced Python programmers. For example, assign-by-reference (apparently built without considering the solutions available in MatLab & R) frequently leads to unexpected changes in the caller's space. I expect that very few people understand linearisation, so multiple inheritance is effectively unusable in Python. C++ would generate a compile-time error if two base classes provided the same method (unless they inherited it from a common virtual base class).

The text in question appears twice in Section 9 of https://docs.python.org/3/tutorial/classes.html. It's in the third paragraph of the introduction and the 5th text paragraph of Section 9.5.
msg411206 - (view) Author: Guido van Rossum (gvanrossum) * (Python committer) Date: 2022-01-21 23:00
You appear more interested in a discussion of Python semantics than in improving the tutorial. I see nothing actionable here.
msg411214 - (view) Author: Jorgen Harmse (jharmse) Date: 2022-01-22 00:21
Is van Rossum serious? I responded to the comments on my report. The action is to clarify the documentation, probably including a warning against multiple inheritance.
History
Date User Action Args
2022-04-11 14:59:54adminsetgithub: 90577
2022-01-22 00:21:30jharmsesetmessages: + msg411214
2022-01-21 23:00:15gvanrossumsetstatus: open -> closed
resolution: wont fix
messages: + msg411206

stage: resolved
2022-01-21 22:52:33jharmsesetmessages: + msg411205
2022-01-21 21:19:55gvanrossumsetmessages: + msg411186
2022-01-21 19:18:42eric.araujosetnosy: + gvanrossum, eric.araujo
messages: + msg411172
2022-01-17 21:03:46jharmsecreate