[Python-3000] PEP: Eliminate __del__
Michael Bayer
mike_mp at zzzcomputing.com
Fri May 4 18:45:07 CEST 2007
On May 4, 2007, at 10:33 AM, Giovanni Bajo wrote:
> On 5/4/2007 4:21 PM, Michael Bayer wrote:
>
>>>
>> why not encapsulate the "proper" weakref-based approach in an easy-
>> to-use method such as "__close__()" ? that way nobody has to
>> guess how to follow this pattern.
>
> Because the idea is that the callback of the weakref will *NOT*
> hold a reference to the object being destroyed, but only to the
> resources that need to be deallocated (that is, to the objects
> bound as attributes of the object).
a __close__() method on a class is first bound to the class, not any
particular self. the Python runtime could detect this and create the
appropriate callable/weakref scenario behind the scenes; not even
binding __close__() to the self in the usual way. obviously it cant
be a pure python solution, it would have to be a specific runtime
supported idea (the same way __metaclass__ or any other magic
attribute is supported).
i just dont understand why such an important feature would have to be
relegated to just a "recipe". i think thats a product of the notion
that "implicit finalizers are bad, use try/finally". thats not
really valid for things like buffers that flush and database/network
connections that must be released when they fall out of scope.
More information about the Python-3000
mailing list