pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

pymethods: add support for `__del__`

Open messense opened this issue 3 years ago • 2 comments

Closes #2479

messense avatar Jun 27 '22 05:06 messense

I found today that if we don't implement tp_dealloc then the default tp_dealloc implementation (at least for CPython) will call tp_finalize. This gives us a potential route to support this and also fix #3064 at the same time.

However the documentation in this area is confusing, as it implies that tp_dealloc doesn't have a default - https://github.com/python/cpython/issues/105018 / https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc

I think it may be possible that we use that default implementation to support this case, but we'll need to test carefully whether this also works for all Python versions, PyPy etc.

davidhewitt avatar May 27 '23 21:05 davidhewitt

I spoke to vstinner (thought no need to ping so no @) briefly about this, I understood that PyObject_CallFinalizerFromDealloc could be added to the limited API in 3.13. So maybe we can figure out a way to proceed with this where __del__ is supported without abi3 for now and then we can add abi3 support on 3.13.

davidhewitt avatar Mar 29 '24 15:03 davidhewitt