Weakrefs to classes that derive from str

Steven Bethard steven.bethard at gmail.com
Wed Mar 30 04:26:27 EST 2005


Ron Garret wrote:
>>Note that you don't need the class redirection:
>>
>>py> ref('')
>>Traceback (most recent call last):
>>   File "<interactive input>", line 1, in ?
>>TypeError: cannot create weak reference to 'str' object
>>
>>But I don't know why strings aren't valid arguments to ref...
> 
> None of the native types (int, float, list, tuple, etc.) can have weak 
> references, but wrapping them in a class is supposed to get around that.  
> And it does -- for all classes except str.

Interesting.  Is the wrapping thing documented somewhere?  I didn't see 
it in the documentation for weakref.ref (though I have been known to be 
blind occasionally) ;)

STeVe



More information about the Python-list mailing list