Re: Weakrefs to classes that derive from str

2005-03-30 Thread Ron Garret
In article <[EMAIL PROTECTED]>, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote: > [Ron Garret] > > Thanks for the detailed explanation. I understand now why you can't > > create weakrefs to these types. What I don't understand still is why > > you can't create weakrefs to user-defined classes th

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Raymond Hettinger
[Ron Garret] > Thanks for the detailed explanation. I understand now why you can't > create weakrefs to these types. What I don't understand still is why > you can't create weakrefs to user-defined classes that inherit from > these types. I would think that instances of user-defined classes have

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Ron Garret
In article <[EMAIL PROTECTED]>, "Raymond Hettinger" <[EMAIL PROTECTED]> wrote: > [Ron Garret] > > Why doesn't this work? > > > > >>> from weakref import ref > > >>> class C(str): pass > > ... > > >>> ref(C()) > > Traceback (most recent call last): > > File "", line 1, in ? > > TypeError: cannot

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Ron Garret
In article <[EMAIL PROTECTED]>, Peter Hansen <[EMAIL PROTECTED]> wrote: > Ron Garret wrote: > foo(int) > foo(float) > foo(dict) > foo(list) > foo(str) > > TypeError: cannot create weak reference to 'C' object > > > foo(tuple) > > TypeError: cannot create weak reference t

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Raymond Hettinger
[Ron Garret] > Why doesn't this work? > > >>> from weakref import ref > >>> class C(str): pass > ... > >>> ref(C()) > Traceback (most recent call last): > File "", line 1, in ? > TypeError: cannot create weak reference to 'C' object . . . > Everything but strs. Also subclasses of tuple are not

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Peter Hansen
Ron Garret wrote: foo(int) foo(float) foo(dict) foo(list) foo(str) TypeError: cannot create weak reference to 'C' object foo(tuple) TypeError: cannot create weak reference to 'C' object foo(long) TypeError: cannot create weak reference to 'C' object Ah, it appears that non-immediate immutable type

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Ron Garret
In article <[EMAIL PROTECTED]>, Peter Hansen <[EMAIL PROTECTED]> wrote: > Steven Bethard wrote: > > Ron Garret wrote: > >> 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 -- fo

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Steven Bethard
Peter Hansen wrote: I believe it's here: http://docs.python.org/lib/module-weakref.html if you search for the string "Not all" and read the next two paragraphs. On the other hand, it says (there) only that "several builtin types such as list and dict ... can add support through subclassing", and do

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Peter Hansen
Steven Bethard wrote: Ron Garret wrote: 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 s

Re: Weakrefs to classes that derive from str

2005-03-30 Thread Steven Bethard
Ron Garret wrote: Note that you don't need the class redirection: py> ref('') Traceback (most recent call last): File "", 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,

Re: Weakrefs to classes that derive from str

2005-03-29 Thread Ron Garret
In article <[EMAIL PROTECTED]>, Steven Bethard <[EMAIL PROTECTED]> 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 "", line 1, in ? > > TypeError: cannot cre

Re: Weakrefs to classes that derive from str

2005-03-29 Thread Steven Bethard
Ron Garret wrote: Why doesn't this work? from weakref import ref class C(str): pass ... ref(C()) Traceback (most recent call last): File "", 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

Weakrefs to classes that derive from str

2005-03-29 Thread Ron Garret
Why doesn't this work? >>> from weakref import ref >>> class C(str): pass ... >>> ref(C()) Traceback (most recent call last): File "", line 1, in ? TypeError: cannot create weak reference to 'C' object >>> Note that this does work: >>> class D(int): pass ... >>> ref(D()) >>> Likewise for