Re: Delegate attribute requests to object

2009-08-13 Thread Gabriel Genellina
En Thu, 13 Aug 2009 12:50:47 -0300, Evan Kroske escribió: I'm trying to use the decorator pattern in a program I'm developing. I want to create a decorator object that works like the object it's decorating except for a few functions. However, I'd rather not hard-code all the identical funct

Re: Delegate attribute requests to object

2009-08-13 Thread Rami Chowdhury
Oops, my apologies, it's the __getattribute__ method you want to call on self.decorated (because __getattr__ won't be there unless you define it specifically) So it should go: def __getattr__(self, request): return self.decorated.__getattribute__(request) On Thu, 13 Aug 2009 11:00

Re: Delegate attribute requests to object

2009-08-13 Thread Rami Chowdhury
More information at http://www.python.org/doc/2.5.2/ref/attribute-access.html if you need it :-) On Thu, 13 Aug 2009 10:13:47 -0700, Evan Kroske wrote: I don't want to inherit from the classes I'm decorating because they have a common superclass. I can make a generic decorator that I can

Re: Delegate attribute requests to object

2009-08-13 Thread Rami Chowdhury
Perhaps I'm misunderstanding something, but I don't think that's really typical decorator behavior? Typically decorators, as I understand them, take an instance argument -- so you wouldn't be saying def __init__(self): self.decorated = Decorated() you'd be saying

Delegate attribute requests to object

2009-08-13 Thread Evan Kroske
I'm trying to use the decorator pattern in a program I'm developing. I want to create a decorator object that works like the object it's decorating except for a few functions. However, I'd rather not hard-code all the identical functionality from the decorated object into the decorator object. Is t