[PEP] auto keyword for automatic objects support in Python

Christos TZOTZIOY Georgiou tzot at sil-tec.gr
Tue Jun 22 11:16:05 CEST 2004


On Fri, 18 Jun 2004 16:32:39 GMT, rumours say that Manlio Perillo
<NOmanlio_perilloSPAM at libero.it> might have written:

[snip]

>With the use of auto there is the need(?) to think at object
>destruction as a two fase operation (like object creation with __new__
>and __init__).
>
>In fact __del__ method is called when the object is being
>deallocated/garbage collected (actually this is not 'deterministic').
>The RAII pattern requires simply that as an object goes 'out of scope'
>it should releases all the 'external resources' it has acquired.
>So there is the need of a second special method (call it __deinit__)
>that should be called for auto objects when they go 'out of scope'
>(in a 'deterministic' way).

[snip]

I'm afraid your PEP's strongest adversary will be the "Explicit is
better than implicit".  You suggest complications to the language
implementation that can be avoided just by user code.

For example, you could have a class Deallocator (untested improvised
code):

class Deallocator:
    def __init__(self, *args):
        self.args = args
    def deallocate(self):
        for obj in self.args:
            obj.__deinit__()

then in your function start:
    auto = Deallocator(obj1, obj2 ...)

and in your function end:
    auto.deallocate()

If your function has multiple exit points, wrap its code in a try ...
finally sequence.


These are some of the obvious counter-arguments for your PEP, and
without looking I assume there have been already similar discussions in
the past.  Good luck :)
-- 
TZOTZIOY, I speak England very best,
"I have a cunning plan, m'lord" --Sean Bean as Odysseus/Ulysses



More information about the Python-list mailing list