[New-bugs-announce] [issue46419] Incomplete Comparison to C++ Methods

Jorgen Harmse report at bugs.python.org
Mon Jan 17 16:03:46 EST 2022


New submission from Jorgen Harmse <jharmse at 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 at python
components: Documentation
messages: 410823
nosy: docs at python, jharmse
priority: normal
severity: normal
status: open
title: Incomplete Comparison to C++ Methods
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46419>
_______________________________________


More information about the New-bugs-announce mailing list