Algorithm for finalizing cycles (Re: [Python-Dev] Garbage collecting closures)
Guido van Rossum
Tue, 15 Apr 2003 15:06:15 -0400
> > > If the object having a finalizer doesn't support references to
> > > arbitrary other objects, then the application cannot make this
> > > object be part of a cycle.
> Greg Ewing <firstname.lastname@example.org> writes:
> > It could make a subclass, though...
> From: email@example.com (Martin v. =?iso-8859-15?q?L=F6wis?=)
> If the type is carefully designed, it can't...
I suppose you have something in mind like this (which is the only way
I can come up with to implement something like a 'final' class in pure
>>> class C(object):
... def __new__(cls):
... if cls is not C: raise TypeError, "haha"
... return object.__new__(cls)
>>> class D(C): pass
>>> a = D()
Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "<stdin>", line 3, in __new__
But how would you prevent this?
>>> a = C()
>>> a.__class__ = D
--Guido van Rossum (home page: http://www.python.org/~guido/)