[Python-Dev] Re: [Python-checkins]python/dist/src/Modules gcmodule.c,2.33.6.5,2.33.6.6

Barry Warsaw barry@python.org
06 Apr 2003 18:03:32 -0400


On Sat, 2003-04-05 at 21:02, Jeremy Hylton wrote:

> #1.  (I think this was Fred's suggestion on Friday.)  Don't do a
> hasattr() check on the object, do it on the class.  This is what happens
> with new-style classes in Python 2.3:  If a new-style class doesn't
> define an __del__ method, then its instances don't have finalizer.  It
> doesn't matter whether the specific instance has an __del__ attribute.

FWIW, IIRC Jython does something vaguely like this.  Actually the
existance of __del__ is check at class creation time because it's
expensive to call __del__ when the object is Java gc'd, and we use two
different Java classes for classic class instances depending on whether
it had a __del__ or not.  This means you can't add __del__ to the class
or the instance after the class is defined.  Personally I think this is
reasonable and I don't recall this biting anyone when I was working on
Jython.

-Barry