Weakrefs to classes that derive from str
Ron Garret
rNOSPAMon at flownet.com
Wed Mar 30 02:20:31 EST 2005
In article <bvednVgyNqMbptffRVn-ig at comcast.com>,
Steven Bethard <steven.bethard at gmail.com> wrote:
> Ron Garret wrote:
> > Why doesn't this work?
> >
> >>>>from weakref import ref
> >>>>class C(str): pass
> > ...
> >>>>ref(C())
> > Traceback (most recent call last):
> > File "<stdin>", line 1, in ?
> > TypeError: cannot create weak reference to 'C' object
>
> 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.
rg
More information about the Python-list
mailing list