When we pass arguments to a decorator we need to create an additional function that accepts those arguments and then returns the actual decorator:
def decorator_creator(*args):
class Decorator(object):
def __init__(self, func):
print args
print func
self.func = func
def __call__(self):
return self.func()
return Decorator
@decorator_creator(1, 2, 3)
def foo():
pass
Output:
(1, 2, 3)
<function foo at 0x0000000002EB9EB8>