You need to do it like this:
def makeDeco(a): def deco(cls): print cls, a return cls return deco >>> @makeDeco(3) ... class Foo(object): ... pass <class '__main__.Foo'> 3
You can use functools.wraps etc. to decorate it, but this is an idea. You need to write a function that returns a decorator. The external function of "creating a decorator" accepts the argument a , and the function of the internal decorator accepts a class.
How it works, when you write @makeDeco(3) , it calls makeDeco(3) . The return value of makeDeco is what is used as a decorator. This is why you need makeDeco to return the function you want to use as a decorator.
source share