On 6/15/20 12:58 PM, M.-A. Lemburg wrote:
Sure, there are often workarounds which can be used, but we do need some way to tell the interpreter "the initialization had a problem, please remove the object from your internal management resources without calling the deallocator".
Perhaps a new public API could be created for this purpose, like you say.
I respectfully disagree. There is purposefully a separation between __new__ and __init__. A failure in __new__ should not call __del__, and a failure in __init__ should be gracefully handled by the __del__. It is not the interpreter's duty to provide an interface that breaks this construct. A c-extension class should not get a pass to do things differently from a python-level class. It is important that CPython not provide interfaces that will make other implementation's lives harder (PyPy, GraalPython, MicroPython). Anyone using C-API functions that start with a "_" should be very thoughtful since those are not meant to be public, usually for good reason.
Matti