Wow: list of immediate subclasses?
Michael Hudson
mwh at python.net
Fri Aug 1 07:14:37 EDT 2003
"Andrew Dalke" <adalke at mindspring.com> writes:
> Carl Banks, responding to Roman Suzi:
> > __subclasses__ is a list of weak references, so the class can be
> > collected even though it's listed in __subclasses__. For whatever
> > reason, class A isn't deleted by reference counts, but cyclic garbage
> > collection gets it.
>
> But I want to know that reason. Why are there any cycles? After
> all, don't weak-references help break cycles? And in my code
> before, why do I need to do the gc a few times to force the cycle
> to be broken?
>
> >>> float.__subclasses__()
> []
> >>> class Spam(float): pass
> ...
> >>> float.__subclasses__()
> [<class '__main__.Spam'>]
> >>> del Spam
> >>> _ = None # just in case ...
This doesn't do what you think it does. The reference to Spam is in
__builtin__._; this only assigns to __main__._.
I don't know where the cycle is, off-hand. I suspect I did once...
[...]
> It's a bit too mysterious for my liking.
I can manage not to care :-)
Cheers,
mwh
--
It's actually a corruption of "starling". They used to be carried.
Since they weighed a full pound (hence the name), they had to be
carried by two starlings in tandem, with a line between them.
-- Alan J Rosenthal explains "Pounds Sterling" on asr
More information about the Python-list
mailing list