Is it possible to pass the decorated method with arguments to __init__
of an decorator?
A simple decorator and usage example
class Decorator(object):
def __init__(self, *args):
print args
def __call__(self, func): # yep the method still have to be callable
return func
@Decorator
def foo():
pass
A decorator without arguments will pass the method as argument
$ python foo.py
(<function foo at 0x7fefd7ac1b90>,)
When I add arguments to the decorator
@Decorator(1, 2, 3)
def foo():
pass
it results in
$ python test.py
(1, 2, 3)
As you can see the method is now missing in the passed arguments.