Re: Automatic delegation in Python 3

2010-09-08 Thread Steven D'Aprano
On Wed, 08 Sep 2010 15:45:46 -0400, Terry Reedy wrote: [...] >> Unfortunately, I need to use delegation, not inheritance, and I need to >> use a new-style class, since I will be using Python 3. How can I do >> automatic delegation in Python 3? Is my only hope to give up on the >> elegance of automa

Re: Automatic delegation in Python 3

2010-09-08 Thread Thomas Jollans
On Wednesday 08 September 2010, it occurred to Steven D'Aprano to exclaim: > What's going on here? I *think* this has something to do with special > double-underscore methods being looked up on the class, not the instance, > for new-style classes, but I'm not entirely sure. Yes, special methods ar

Re: Automatic delegation in Python 3

2010-09-08 Thread Terry Reedy
On 9/8/2010 9:58 AM, Steven D'Aprano wrote: Delegation in old-style classes worked fine: # Python 2.6 class Delegate: ... def __init__(self, x): ... self.__dict__['x'] = x ... def __getattr__(self, name): ... return getattr(self.x, name) ... def __setattr__(