Decorator to inject function into __call__ of a class

Patrick Maupin pmaupin at
Sat Mar 13 17:26:15 CET 2010

On Mar 13, 10:19 am, Jon Clements <jon... at> 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, **kw):
        self.func = func
        self.args = args = kw
    def __call__(self):
        self.func(*self.args, **

Or exactly what are you looking for?


More information about the Python-list mailing list