[Python-3000] Removing __del__

Giovanni Bajo rasky at develer.com
Tue Sep 19 23:42:43 CEST 2006


Michael Chermside <mcherm at mcherm.com> wrote:

> Since we're apparently still in "propose wild ideas" mode for Py3K
> I'd like to propose that for Py3K we remove __del__. Not "fix" it,
> not "tweak" it, just remove it and perhaps add a note in the manual
> pointing people to the weakref module.


I don't use __del__ much. I use it only in leaf classes, where it surely can't
be part of loops. In those rare cases, it's very useful to me. For instance, I
have a small classes which wraps an existing handle-based C API exported to
Python. Something along the lines of:

class Wrapper:
    def __init__(self, *args):
           self.handle = CAPI.init(*args)

    def __del__(self, *args):
            CAPI.close(self.handle)

    def foo(self):
            CAPI.foo(self.handle)

The real class isn't much longer than this (really). How do you propose to
write this same code without __del__?

Notice that I'd be perfectly fine with the __close__ semantic prosed in this
thread (might be called more than once, order within the loop doesn't matter).

Giovanni Bajo



More information about the Python-3000 mailing list