Proposal: local variable declarations and type advice

Paul Rubin phr-n2002a at nightsong.com
Wed Feb 27 16:32:45 EST 2002


Jeff Shannon <jeff at ccvcorp.com> writes:
> > Also, there's no way to make sure that the "del temp" at the end of
> > a block actually gets run, unless you put try...finally around it,
> > which is a big mess.
> 
> I may be in way out of my depth here, but I don't think that this is
> true.  If you explicitly delete an object, then that name should be
> guaranteed to be unbound.  What's *not* guaranteed, is whether or
> not an unreferenced object's __del__() method gets called -- the
> object may still exist in memory, unreachable, somewhere.  However,
> that name is *not* going to reference it properly.
> 
> At least, that's my understanding of it.

What I mean is if you say

  if x:
    temp = frob()
    mumble(temp)
    foo()
    bar()
    del temp

and the foo() or one of the other calls raises an exception that's caught
by some outer block in the same function, then temp hasn't been deleted,
and in fact the code could even depend on it not being deleted.  So del
doesn't give you the same effect as local scope.



More information about the Python-list mailing list