[Python-Dev] Re: pickle me, Elmo? (weakref feature request)

Arne Koewing ark@gmx.net
Mon, 10 Feb 2003 20:14:42 +0100


Is this the right time to post a feature request ?

It's about pickling weakrefs:

let's assume i 've created 3 class instances

>>> class A:
...     pass

>>> a = A()
>>> b = A()
>>> c = A()
>>> a.b = b                  #put b into a
>>> a.ref_b = weakref.ref(b) #weakref to b
>>> a.ref_c = weakref.ref(c) #weakref to c

now i pickle around

>>> data = pickle.dumps(a)
>>> new_a = pickle.loads(data)

now i would like to have:

new_a       is my unpickled a
new_a.b     is my unpickled b
new_a.ref_b is an weakref to new_a.b
new_a.ref_c is an dead weakref 
(c was not pickled because it's just weakly-referenced)


weakrefs are not supported by the default, but this kind of 'support' 
could not (i didn't get it ;) be added using the  copy_reg module,
but it seems to be very useful;

weakrefs could used as an "pickling-barrier"...

what do you think?


Arne