Re: The untimely dimise of a weak-reference

2010-08-03 Thread Gregory Ewing
Bruno Desthuilliers wrote: Would be better with : return self.func(obj, *args, *kwds) Thanks -- well spotted! -- Greg -- http://mail.python.org/mailman/listinfo/python-list

Re: The untimely dimise of a weak-reference

2010-08-02 Thread Bruno Desthuilliers
Gregory Ewing a écrit : (snip) import weakref class weakmethod(object): def __init__(self, bm): self.ref = weakref.ref(bm.im_self) self.func = bm.im_func def __call__(self, *args, **kwds): obj = self.ref() if obj is None: raise ValueError("Calling dead weak method")

RE: The untimely dimise of a weak-reference

2010-08-01 Thread Vincent van Beveren
I run into. Regards, Vincent -Original Message- From: python-list-bounces+v.vanbeveren=rijnhuizen...@python.org [mailto:python-list-bounces+v.vanbeveren=rijnhuizen...@python.org] On Behalf Of Christian Heimes Sent: vrijdag 30 juli 2010 16:44 To: python-list@python.org Subject: Re: The untimely

RE: The untimely dimise of a weak-reference

2010-08-01 Thread Vincent van Beveren
Hi Gregory, > You can create your own wrapper that keeps a weak reference to > the underlying object. Here's an example. > [...] Thanks for the code! Regards, Vincent -- http://mail.python.org/mailman/listinfo/python-list

Re: The untimely dimise of a weak-reference

2010-07-30 Thread Gregory Ewing
Vincent van Beveren wrote: I was working with weak references in Python, and noticed that it > was impossible to create a weak-reference of bound methods. > is there anything I can do about it? You can create your own wrapper that keeps a weak reference to the underlying object. Here's an exa

Re: The untimely dimise of a weak-reference

2010-07-30 Thread Christian Heimes
Am 30.07.2010 16:06, schrieb Vincent van Beveren: > I did not know the object did not keep track of its bound methods. What > advantage is there in creating a new bound method object each time its > referenced? It seems kind of expensive. Instances of a class have no means of storing the bound m

RE: The untimely dimise of a weak-reference

2010-07-30 Thread Peter Otten
Vincent van Beveren wrote: > I did not know the object did not keep track of its bound methods. What > advantage is there in creating a new bound method object each time its > referenced? It seems kind of expensive. While I didn't measure it I suppose that it saves a lot of memory. Peter -- htt

RE: The untimely dimise of a weak-reference

2010-07-30 Thread Vincent van Beveren
: vrijdag 30 juli 2010 15:06 To: python-list@python.org Subject: Re: The untimely dimise of a weak-reference Vincent van Beveren wrote: > Hi everyone, > > I was working with weak references in Python, and noticed that it was > impossible to create a weak-reference of bound methods. Here

Re: The untimely dimise of a weak-reference

2010-07-30 Thread Peter Otten
Vincent van Beveren wrote: > Hi everyone, > > I was working with weak references in Python, and noticed that it was > impossible to create a weak-reference of bound methods. Here is a little > python 3.0 program to prove my point: > > import weakref > > print("Creating object...") > class A(obj

The untimely dimise of a weak-reference

2010-07-30 Thread Vincent van Beveren
Hi everyone, I was working with weak references in Python, and noticed that it was impossible to create a weak-reference of bound methods. Here is a little python 3.0 program to prove my point: import weakref print("Creating object...") class A(object): def b(self): print("I a