[Python-Dev] Why aren't more things weak referencable

"Martin v. Löwis" martin at v.loewis.de
Mon May 31 03:56:18 EDT 2004


Raymond Hettinger wrote:
> Instances of classes inheriting from str, tuple, etc cannot be weakly 
> referenced.  Does anyone know the reason for this?

In addition to the reason Christian gave, one (conceptually more
important) reason is that strings can't participate in cycles. Weak
references were introduced as a mechanism to avoid creating cyclic
structures, so that "backward" links could be made weak references.

It appears that people have then been eager to add weakref support
to other datatypes. IMO, they have been too eager. For example, I
can't see a reason why Unicode objects should be weakly referencable
(just as I can't see a reason for plain strings).

Regards,
Martin




More information about the Python-Dev mailing list