On 01/02/2021 23:50, Greg Ewing wrote:
On 2/02/21 12:13 am, Phil Thompson via Python-Dev wrote:
TypeError: object.__new__(B) is not safe, use B.__new__()
It's not safe because object.__new__ doesn't know about any C-level initialisation that A or B need.
But A.__new__ is calling object.__new__ and so can take care of its own needs after the latter returns.
At the C level, there is always a *single* inheritance hierarchy.
Why?
The right thing is for B's tp_new to directly call A's tp_new, which calls object's tp_new.
I want my C-implemented class's __new__ to support cooperative multi-inheritance so my A class cannot assume that object.__new__ is the next in the MRO. I did try to call the next-in-MRO's tp_new directly (rather that calling it's __new__ attribute) but that gave me recursion errors.
Don't worry about Python-level multiple inheritance; the interpreter won't let you create an inheritance structure that would mess this up.
Phil