Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Steven D'Aprano
On Sat, 13 Mar 2010 11:02:44 -0800, Jon Clements wrote: > If I can re-explain slightly, say I have a class 'compute': > > class Compute(object): > def __init__(self, something): > self.something = something > # misc other methods here. > > then... > > class ComputeAdd(Comput

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jon Clements
On 13 Mar, 17:42, Jack Diederich wrote: > On Sat, Mar 13, 2010 at 12:10 PM, Jon Clements wrote: > > On 13 Mar, 16:42, Jack Diederich wrote: > >> On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements > >> wrote: > >> > This is semi-experimental and I'd appreciate opinions of whether it's > >> > the co

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Stephen Hansen
On Sat, Mar 13, 2010 at 8:19 AM, Jon Clements wrote: > The name 'some_function' is completely redundant -- don't need it, > don't actually care about the function afterwards, as long as it > becomes a __call__ of a 'B' *instance*. > Special methods are looked up on the class, not the instance, s

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jack Diederich
On Sat, Mar 13, 2010 at 12:10 PM, Jon Clements wrote: > On 13 Mar, 16:42, Jack Diederich wrote: >> On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: >> > This is semi-experimental and I'd appreciate opinions of whether it's >> > the correct design approach or not. It seems like a good idea,

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jon Clements
On 13 Mar, 16:42, Jack Diederich wrote: > On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: > > This is semi-experimental and I'd appreciate opinions of whether it's > > the correct design approach or not. It seems like a good idea, but it > > doesn't mean it is. > > > I have a class 'A', thi

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Patrick Maupin
On Mar 13, 10:38 am, Jon Clements wrote: > On 13 Mar, 16:26, Patrick Maupin wrote: > > > > > On Mar 13, 10:19 am, Jon Clements wrote: > > > > What I'd like to achieve is something similar to: > > > > @inject(B): > > >  def some_function(a, b): > > >      pass # something useful > > > So, just ty

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jack Diederich
On Sat, Mar 13, 2010 at 11:19 AM, Jon Clements wrote: > This is semi-experimental and I'd appreciate opinions of whether it's > the correct design approach or not. It seems like a good idea, but it > doesn't mean it is. > > I have a class 'A', this provides standard support functions and > excepti

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Jon Clements
On 13 Mar, 16:26, Patrick Maupin wrote: > On Mar 13, 10:19 am, Jon Clements wrote: > > > What I'd like to achieve is something similar to: > > > @inject(B): > >  def some_function(a, b): > >      pass # something useful > > So, just typing at the keyboard here, you mean something like: > > class

Re: Decorator to inject function into __call__ of a class

2010-03-13 Thread Patrick Maupin
On Mar 13, 10:19 am, Jon Clements wrote: > What I'd like to achieve is something similar to: > > @inject(B): >  def some_function(a, b): >      pass # something useful So, just typing at the keyboard here, you mean something like: class InjectClass(object): def __init__(self, func, *args, *

Decorator to inject function into __call__ of a class

2010-03-13 Thread Jon Clements
This is semi-experimental and I'd appreciate opinions of whether it's the correct design approach or not. It seems like a good idea, but it doesn't mean it is. I have a class 'A', this provides standard support functions and exception handling. I have 'B' and 'C' which specialise upon 'A' What I'