"Martin v. Löwis" wrote:
Raymond Hettinger wrote:
Instances of classes inheriting from str, tuple, etc cannot
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).
Never rule out "foolish" consistencies. I can imagine a system where multiple, heterogeneous values all get run through a weakref processor; to have string objects pass through without Yet Another try/except would be a design and maintenance boon.
Quite similar to my current "pet peeve":
None > 3
None > 'hoopy'
None > True
None > datetime.date(2004, 5, 31)
Traceback (most recent call last): File "<interactive input>", line 1, in ? TypeError: can't compare datetime.date to NoneType
...writing an O-R mapper, this particular hobgoblin bites me rather often ;)
Robert Brewer MIS Amor Ministries email@example.com