New submission from Jorgen Harmse <jhar...@roku.com>:

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__.)

----------
assignee: docs@python
components: Documentation
messages: 410823
nosy: docs@python, jharmse
priority: normal
severity: normal
status: open
title: Incomplete Comparison to C++ Methods
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue46419>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to