[Python-Dev] Design question: call del only after successful init? (original) (raw)

Ka-Ping Yee ping@lfw.org
Fri, 3 Mar 2000 01:00:21 -0800 (PST)


On Thu, 2 Mar 2000, Greg Stein wrote:

On Thu, 2 Mar 2000, Guido van Rossum wrote: >... > But it is just as likely that calling del on a partially > uninitialized object is a bad mistake, and I am doing all these cases > a favor by not calling del when init failed! > > Any opinions? If nobody speaks up, I'll make the change.

+1 on calling del IFF init completes successfully.

That would be my vote as well.

What convinced me of this is the following:

If it's up to the implementation of del to deal with a problem that happened during initialization, you only know about the problem with very coarse granularity. It's a pain (or even impossible) to then rediscover the information you need to recover adequately.

If on the other hand you deal with the problem in init, then you have much better control over what is happening, because you can position try/except blocks precisely where you need them to deal with specific potential problems. Each block can take care of its case appropriately, and re-raise if necessary.

In general, it seems to me that what you want to do when init runs afoul is going to be different from what you want to do to take care of object cleanup in del. So it doesn't belong there -- it belongs in an except: clause in init.

Even though it's an incompatibility, i really think this is the right behaviour.

-- ?!ng

"To be human is to continually change. Your desire to remain as you are is what ultimately limits you." -- The Puppet Master, Ghost in the Shell