tuple weakref

Robin Becker robin at jessikat.fsnet.co.uk
Sun Apr 13 12:55:20 EDT 2003


In article <m38yuepdva.fsf at mira.informatik.hu-berlin.de>, Martin v.
Löwis <martin at v.loewis.de> writes
>Robin Becker <robin at jessikat.fsnet.co.uk> writes:
>
>> What's the correct incantation to get a weak reference to a tuple? The
>> rather obvious wrapper approach fails as the wrapper dies immediately
>> 
>> ie weakref.ref(Wrapper((....)))
>
>What is 'Wrapper'?
>
>Tuples are not weakly-referencable, unless you change the source code
>of tupleobject.c.
>
>Regards,
>Martin

class Wrapper:
        def __init__(self,p):
                self.p = p

Well I actually want to do
        
        self.parent = weakref.ref(parent)

inside a class __init__, unfortunately parent is a tuple (or None).
Strictly speaking with gc I can do without the weakref as gc will
resolve and break any loop. As you say tuples (and the None object)
aren't weakrefable (for some reason).

The trivial silly solution is to attempt to hide the tupleness inside
another class, but that won't work as the wrapper dies immediately.

The tuples are coming from pyRXP's tuple tree representation.  
-- 
Robin Becker




More information about the Python-list mailing list