Steven Bethard wrote:
> Wildemar Wildenburger wrote:
>
> class Observable(object):
>
>> ... def __init__(self, func, instance=None, observers=None):
>> ... self.func = func
>> ... self.instance = instance
>> ... self.observers = observers or []
>>
Wildemar Wildenburger wrote:
class Observable(object):
> ... def __init__(self, func, instance=None, observers=None):
> ... self.func = func
> ... self.instance = instance
> ... self.observers = observers or []
Unless you also changed code in __get__, this means yo
Peter Otten wrote:
class Descriptor(object):
> ... def __get__(*args): return object()
> ...
>
class SomeActor(object):
> ... meth = Descriptor()
> ...
>
SomeActor.meth is SomeActor.meth
> False
>
Of course ...
Man, this lang
David Wahler wrote:
> On Jun 2, 12:27 am, Steven Bethard <[EMAIL PROTECTED]> wrote:
>> I think you want to define __get__ on your Observable class so that it
>> can do the right thing when the method is bound to the instance:
[snip]
> Is this desired behavior?
>
a = SomeActor()
b = SomeA
Wildemar Wildenburger wrote:
> Thanks for the thorough explanation. But you did mock me with that
> "SomeActor.meth is SomeActor.meth"-line, right? ;)
Acually, no:
>>> class Descriptor(object):
... def __get__(*args): return object()
...
>>> class SomeActor(object):
... meth = Descriptor
David Wahler wrote:
>
> Here's my attempt at an implementation that works as a decorator. It
> stores the observers in a dictionary attribute of the instance, using
> the method name as a key. For example:
>
>
> [snip: another nice aproach]
> Anyway, these are just my initial thoughts -- I don't
Peter Otten wrote:
> Then you have modified the code posted by Steven Bethard.
>
>
Oops. Indeed I did.
I changed this
>>> class Observable(object):
... def __init__(self, func, instance=None, observers=None):
... if observers is None:
... observers = []
... self.
On Jun 2, 3:00 pm, Peter Otten <[EMAIL PROTECTED]> wrote:
> Then you have modified the code posted by Steven Bethard.
>
> > I don't see how your behaviour should come about ... a new observer-list
> > is created for every decorated method, so there is no problem.
>
> Yes, but that list is shared a
Wildemar Wildenburger wrote:
> David Wahler wrote:
>> Is this desired behavior?
>>
>>
> a = SomeActor()
> b = SomeActor()
> a.meth.observers is b.meth.observers
>
>> True
>>
> No it's not, but I get
>
a = SomeActor()
b = SomeActor()
a.meth.observers i
David Wahler wrote:
> Is this desired behavior?
>
>
a = SomeActor()
b = SomeActor()
a.meth.observers is b.meth.observers
> True
>
No it's not, but I get
>>> a = SomeActor()
>>> b = SomeActor()
>>> a.meth.observers is b.meth.observers
False
I don't see how your
On Jun 2, 12:27 am, Steven Bethard <[EMAIL PROTECTED]> wrote:
> I think you want to define __get__ on your Observable class so that it
> can do the right thing when the method is bound to the instance:
>
> >>> class Observable(object):
> ... def __init__(self, func, instance=None, observers=No
En Fri, 01 Jun 2007 21:25:50 -0300, Wildemar Wildenburger
<[EMAIL PROTECTED]> escribió:
> Steven Bethard wrote:
>> I think you want to define __get__ on your Observable class so that it
>> can do the right thing when the method is bound to the instance:
>
> It took me quite some time understand
Steven Bethard wrote:
> I think you want to define __get__ on your Observable class so that it
> can do the right thing when the method is bound to the instance:
>
> >>> class Observable(object):
> [snip]
> ... def __get__(self, obj, cls=None):
> ... if obj is None:
> ... re
Wildemar Wildenburger wrote:
> I thought: I'll just write a decorator that lets me react to method
> calls easily (the ever so popular observer-pattern). I've looked at some
> recepies, but I just don't get them (I'm feeling kinda dumb today, sorry).
[snip]
> This is more complicated than expecte
Hello folks :)
This has got to be an FAQ, but somehow I can't seem to find an answer
that I understand ...
I thought: I'll just write a decorator that lets me react to method
calls easily (the ever so popular observer-pattern). I've looked at some
recepies, but I just don't get them (I'm feelin
15 matches
Mail list logo