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
[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
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
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
[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
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
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
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
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
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,
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
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
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
13 matches
Mail list logo